I have a list made up of several data frames. I would like to remove all of the columns with NAs in each data frame. Note the columns to be removed are not the same in each
Julius' answer is great, but since I already started writing...
Your question is a little ambiguous, but if you want to remove any row with an NA
from each data.frame in your list:
lapply(WW1_Data, na.omit)
Or you can use your own function, assuming each data.frame in your list only has one row like these do:
myfun <- function(x) {
x[, !is.na(x)]
}
lapply(WW1_Data, myfun)
Or switch to a single data.frame, melt it and remove rows:
out <- do.call(rbind, WW1_Data)
out.m <- melt(out, id.vars='Site_Name')
na.omit(out.m)
Try this
lapply(WW1_Data, function(x) x[, !is.na(x)])
$Alnön
Site_Name X1996 X2000 X2010
1 Alnön 0.3076923 0.2608696 0.08333333
$Ammarnäs
Site_Name X1996 X2011
2 Ammarnäs 0.75 0.8
...