I have a dataframe:
a<-c(1,2,3)
b<-c("CarA","CarB",NA)
data<-data.frame(a,b)
data
a b
1 1 CarA
2 2 CarB
3 3 NA
Now I want to remove the row with missing data (NA).
But this does not work:
data<-data[data[,2]!=NA,]
My thinking here is to look at the second column [,2] and look for those that don't have NA. Then extract the remaining data. Would someone be able to tell me what went wrong here?
Wouldn't
do? It seems the cleanest and fastest way to me.
By the way, your code does not work because you cannot do
!=NA
Use
is.na()
instead (butna.omit()
is better):