Select only rows if the value in a particular set of columns is 'NA' in R -
i have data frame many rows , columns in (3000x37) , want able select rows may have >= 2 columns of value "na". these columns have data of different data types. know how in case want select 1 column via:
df[is.na(df$col.name), ]
how make selection if want select 2 (or more) columns?
first create vector nn
of number of na's in each row , select rows >= 2 na's d[nn>=2,]
d = data.frame(x=c(na,1,2,3), y=c(na,"a",na,"c")) nn = apply(d, 1, fun=function (x) {sum(is.na(x))}) d[nn>=2,] x y 1 na <na>
Comments
Post a Comment