0

I have a data.frame in R which looks like this:

df<- data.frame("x" = c(1,4,5,7,4,32,2,5), "y"=c(NA,NA,"1", NA, "2", "1", NA, NA))
df$y <- as.character(df$y)

and I want to get rid of all rows, that contain a "1" or "2" in the column $y without dropping rows containing NAs (which are all others).

df[df$y!="1",]

sets all values NA that contain a NA or a "1" in the column.

Sotos
  • 51,121
  • 6
  • 32
  • 66
Droney
  • 179
  • 1
  • 4

0 Answers0