I have a database like the following
Var1 Var2 Var3 X Y Z
VIX SPX VOL 2 3 4
SPX VIX NA 4 4 NA
SPX NA NA 2 NA NA
We can use
apply row-wise for the first three columns and check with
grepl if it has any of the three possible values and finally using
all we verify that all the three columns for that row has the accepted values.
df[apply(df[1:3], 1, function(x) all(grepl("VIX|SPX|VOL", x))), ] # Var1 Var2 Var3 X Y Z #1 VIX SPX VOL 2 3 4
Or as @Cath mentioned in the comments using the above can result into selecting some unnecessary rows. We can change it to
df[apply(df[1:3], 1, function(x) all(c("VIX", "SPX", "VOL") %in% x)), ]
to ensure that all three unique values are present in the three columns.