Reputation: 1446
I have a list of data.frames and some of them are filled with NA, I would like to remove those data.frames with only NA in my list.
I am using these two commands:
list.df <- lapply(list.df, na.omit)
list.df <- list.df[sapply(list.df, function(x) dim(x)[1] >0 )]
Is there a way to do the same but in one line?
Upvotes: 1
Views: 588
Reputation: 7113
This keeps all data.frame
s which have at least one NA
-free row:
df.list[ sapply( df.list, function(x){ any( rowSums(is.na(x)) == 0 ) }) ]
Upvotes: 2