Let's say I want to write a function like:
Fn <- function(df, to_remove = NULL) {
df <- df[!df %in% to_remove,]
}
The purpose is to remove all values in a row (not row numbers/indices/names) where one of the values is equal to value(s) specified in to_remove.
Any idea why this doesn't work without specifying a column?
Example:
df <- data.frame(a = c("a", "a", "a"), b = c("a", "b", "a"))
a b
1 a a
2 a b
3 a a
Expected output:
a b
1 a a
3 a a
I'm looking for a base R or data.table solution.
to_removeargument appears in any column? You might check out thefilter_*variants indplyr, e.g (filter_all).