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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -