0

I have a dataset like that

v1   v2   v3
1    NA   NA
2    1    NA
3    NA   2
4    NA   NA
5    9    0
6    0    2

I want to subset a dataframe that both not contain missing values. The desired outcome should be:

   v1   v2   v3
    5    9    0
    6    0    2

I use follwoing syntax, but it seems is.na could not be applied to a specific vector

mydata<-mydata[with(mydata, any(!is.na(mydata$v2) & !is.na(mydata$v3))),] 


**The warning message is that**
is.na() applied to non-(list or vector) of type 'NULL' 

Could anyone point me in the right direction?

Jaap
  • 71,900
  • 30
  • 164
  • 175
eclo.qh
  • 145
  • 1
  • 2
  • 8
  • 4
    `mydf[complete.cases(mydf),]`? – Jaap Jan 14 '16 at 21:17
  • Thank you so much @Jaap, it works! But It seems that the function `complete.cases()` can delete the observations having missing values across all columns. If I just want to specify the two columns "v2" and "v3", and to discard the observations that contains the "NA" in either this two columns, how to deal with that? Thanks in advance. – eclo.qh Jan 14 '16 at 21:37
  • `mydf[complete.cases(mydf[, c("v2","v3")]),]` – Jaap Jan 14 '16 at 21:39
  • Furthermore, read through the answers in the linked question. They provide a lot of information on how to deal with `NA` values in diferent cases. – Jaap Jan 14 '16 at 21:41
  • Thank you @Jaap, it is really helpful. – eclo.qh Jan 14 '16 at 21:50

0 Answers0