You can achieve this by using the %in% operator in R along with the apply function to check each row of the dataframe against the columns of another dataframe. Here is an example:
main.r400 chars19 lines
In this example, apply is used to apply a function to each row of df1. The function checks if any of the values in the row are present in df2 using the %in% operator. The unlist function is used to convert the dataframes into vectors, which can be compared using %in%. The result is a boolean vector indicating which rows to remove. The ! operator is used to negate this vector and select the rows that do not contain the variables.
Alternatively, you can use the dplyr package to achieve the same result:
main.r362 chars20 lines
In this example, rowwise is used to perform the comparison row by row, c_across is used to select all columns, and filter is used to remove the rows that contain the variables.
gistlibby LogSnag