1

I have the following dataframe:

DF <- data.frame(x = c(1, 2, 3,NA), y = c(1,0, 10, NA), z=c(43,NA, 33, NA))

If I want to omit only x = NA and z = NA.

complete.cases deletes all the row contains NA for desired column.

Therefore, I am not sure how to only delete the last row in the dataframe DF.

John Paul
  • 12,196
  • 6
  • 55
  • 75
user1489975
  • 1,841
  • 2
  • 14
  • 8

1 Answers1

1

Not clear whether you want to exclude rows where x OR z = NA or x AND z = NA. Change the boolean from and & to or | if that's the case:

> DF[!(is.na(DF$x) & is.na(DF$z)),]
  x  y  z
1 1  1 43
2 2  0 NA
3 3 10 33
Chase
  • 67,710
  • 18
  • 144
  • 161