0

I have around more than 1000 columns in my data frame that only has NA values throughout. Is there a function in R which could remove columns that have NA values throughout?

  • Can't find a duplicate. Here's a **self promotion** comment: `mde::drop_na_if(airquality,sign="eq",percent_na=100)` There exist simpler ways like `complete.cases`,`drop_na`(`tidyr`), etc from [mde](https://www.github.com/Nelson-Gon/mde) that I wrote. – NelsonGon Mar 26 '20 at 11:52

2 Answers2

0

Not one function but

df[,colSums(apply(df,2,is.na))<nrow(df)]
user2974951
  • 9,535
  • 1
  • 17
  • 24
0
d <- data.frame(a = c(NA, rep(1, 9)),
                b = rep(NA, 10))

d[vapply(d, function(x) all(!is.na(x)), logical(1))]
r.user.05apr
  • 5,356
  • 3
  • 22
  • 39