EDIT: tried grepl, as in:
DF <- DF[!grepl("M+1", DF$Column2, fixed=TRUE),]
(the fixed=TRUE
is necessary because of the "+" in the string).
Original post:
My data frame contains a particular column that has a wide range of factors, and I want to delete any row in which that factor contains a particular string.
For example, I want to delete rows 1 and 3 from the table below, because they contain the conserved string "M+1".
Column1 Column2 Column3
x [3]M+1 y
x y
x [2]M+1 y
x y
I'd be fine if the column entry was just a static string, e.g.
DF <- DF[!(DF$Column2 == "M+1"),]
But unfortunately there are other, irrelevant components to the factors in the column. I considered using %in%
but can't figure out how to make it "not in" rather than "in". I've tried here, here, here and here etc. but they're mainly dealing with deleting rows based on numeric values rather than factors (and based on the absolute value in the column, rather than whether it "contains" a particular value). Thanks.