title: Remove NA columns in a list of dataframes
body: <p>I am having some trouble cleaning data that I imported from Excel with <code>readxl</code>. <code>readxl</code> created a large list of objects with classes = <code>c('data.frame', tbl_df, tbl)</code> (I would also like to know about why/how it has multiple classes assigned to it). Each of those objects is one of the sheets in the original Excel workbook. The problem is that each of those objects (sheets) may have many columns entirely filled with NAs. I have scanned through stackoverflow and found some similar problems and tried to apply the given solutions like <a href="https://stackoverflow.com/questions/11797621/remove-columns-with-nas-from-all-dataframes-in-list">here</a> and <a href="http://r.789695.n4.nabble.com/remove-NAs-from-list-collectively-td4369074.html" rel="nofollow noreferrer">here</a> (the first one is the most like my problem). However when I try this:</p>
  
  <pre><code>lapply(x, function(y) y[, !is.na(y)])
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Error in `[.data.frame`(y, , !is.na(y)) : undefined columns selected
  </code></pre>
  
  <p>I've also tried this: </p>
  
  <pre><code>lapply(x, function(y) y[!is.na(y)]
  </code></pre>
  
  <p>but it reduces all of my dataframes to only the first column. I think I know it's something to do with my dataframe-within-list syntax. I've experimented with different iterations of <code>y[[]][]</code> and even recently found this interesting pattern in <code>lapply</code>: <code>lapply(x, "[[", y)</code>, but couldn't make it work.</p>
  
  <p>Here are the first two objects in my list of dataframes (any hints on how to be more efficient in <code>dput</code>-ing this data are also appreciated). As you can see, the first object has no NA columns, whereas the second has 5 NA columns. I would like to remove those 5 NA columns, but do so for all objects in my list.</p>
  
  <p>Any help is greatly appreciated!</p>
  
  <pre><code>dput(head(x[[1]]))
  structure(list(Date = structure(c(1305504000, 1305504000, 1305504000, 
  1305504000, 1305504000, 1305504000), class = c("POSIXct", "POSIXt"
  ), tzone = "UTC"), Time = structure(c(-2209121912, -2209121612, 
  -2209121312, -2209121012, -2209120712, -2209120412), class = c("POSIXct", 
  "POSIXt"), tzone = "UTC"), Level = c(106.9038, 106.9059, 106.89, 
  106.9121, 106.8522, 106.8813), Temperature = c(6.176, 6.173, 
  6.172, 6.168, 6.166, 6.165)), .Names = c("Date", "Time", "Level", 
  "Temperature"), row.names = c(NA, 6L), class = c("tbl_df", "tbl", 
  "data.frame"))
  
  dput(head(x[[2]]))
  structure(list(Date = structure(c(1305504000, 1305504000, 1305504000, 
  1305504000, 1305504000, 1305504000), class = c("POSIXct", "POSIXt"
  ), tzone = "UTC"), Time = structure(c(-2209121988, -2209121688, 
  -2209121388, -2209121088, -2209120788, -2209120488), class = c("POSIXct", 
  "POSIXt"), tzone = "UTC"), LEVEL = c(117.5149, 117.511, 117.5031, 
  117.5272, 117.4523, 117.4524), TEMPERATURE = c(5.661, 5.651, 
  5.645, 5.644, 5.644, 5.645), `NA` = c(NA_real_, NA_real_, NA_real_, 
  NA_real_, NA_real_, NA_real_), `NA` = c(NA_real_, NA_real_, NA_real_, 
  NA_real_, NA_real_, NA_real_), `NA` = c(NA_real_, NA_real_, NA_real_, 
  NA_real_, NA_real_, NA_real_), `NA` = c(NA_real_, NA_real_, NA_real_, 
  NA_real_, NA_real_, NA_real_), `NA` = c(NA_real_, NA_real_, NA_real_, 
  NA_real_, NA_real_, NA_real_)), .Names = c("Date", "Time", "LEVEL", 
  "TEMPERATURE", NA, NA, NA, NA, NA), row.names = c(NA, 6L), class =    
  c("tbl_df", "tbl", "data.frame"))
  </code></pre>