I'm using a df with the following structure:
A <- c(1:3)
B <- c("Sweet", "Home", "Sweet Home")
df <- data.frame(A,B)
| A | B |
|---|---|
| 1 | Sweet |
| 2 | Home |
| 3 | Sweet Home |
I want to be able to drop all the rows that contain the word "Sweet", unless they contain the word "Home".
I have been using the following code:df1 <- df[!grepl("Sweet", df$B),] but this deletes both rows 1 and 3, like so:
| A | B |
|---|---|
| 2 | Home |
How can I do this so I can keep the values where Sweet has Home in it, too?