I have two data frames. One, we'll call df, is very large with multiple columns and rows. One such column is "admin" and another is "name."
I created a second data frame called xmatches by searching for indices of rows that contain a certain admin and a certain name. I would like to remove these rows from df. How would I achieve this?
I tried just so I could take a look at what I might be removing and it threw an error (I am very new at this, but did expect some error which is why I didn't attempt an actual removal here.)
a_df[xmatches]
Error:
Can't subset columns past the end.
ℹ Locations 52762, 52763, 52764, …, 52981, and 52982 don't exist.
ℹ There are only 16 columns.
Run `rlang::last_error()` to see where the error occurred.
CodePudding user response:
Why make a separate matches df? Just do:
df <- df %>%
filter(!str_detect(colA, some_regex) & !str_detect(colB, some_regex))
Alternatively, if there is only one admin and name to remove:
df <- df %>%
filter(name_col != name & admin_col != admin)
Let me know if this works.