I am trying to replicate the success of this solution:
remove columns with NAs from all dataframes in list
or
Remove columns from dataframe where some of values are NA
with a list of dataframes:
m1<- structure(list(vPWMETRO = c(1520L, 1520L, 1520L, 1520L, 1520L),
vPWPUMA00 = c(500L, 900L, 1000L, 1100L, 1200L),
v100 = c(96.1666666666667, 71.4615384615385, 68.6363636363636, 22.5, 64.5),
v101 = c(5, 15, NA, NA, NA),
v102 = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_)),
.Names = c("vPWMETRO", "vPWPUMA00", "v100", "v101", "v102"),
row.names = 26:30, class = "data.frame")
m2<- structure(list(vPWMETRO = c(6440L, 6440L, 6440L, NA, NA),
vPWPUMA00 = c(1300L,2100L, 2200L, NA, NA),
v100 = c(38.3921568627451, 35, 12.5, NA, NA),
v101 = c(NA, NA, NA, NA, NA),
v102 = c(38.3333333333333, 68, NA, NA, NA)),
.Names = c("vPWMETRO", "vPWPUMA00", "v100", "v101", "v102"),
row.names = c("39", "40", "41", "NA", "NA.1"), class = "data.frame")
#views structure
str(m1)
str(m2)
#creates list
snag<- list(v1520=m1, v6440=m2)
str(snag)
#attempts lapply solution
prob1<- lapply(snag, function(y) y[ ,!is.na(y)])
#2nd attempt, same result on just dataframe:
x5$v6440[ , apply(x5$v6440, 2, function(x) !(is.na(x)))]
So that columns that contain all NA's are deleted within the dataframe. Thus the result should be a list of 2 df's:
v1520: vPWPUMA00, v100, v101
v6440: vPWPUMA00, v100, v102
I see the difference in the example problem is that the dimension is 1x11 and my dimensions are 5x5. I am guessing this causes the "undefined column" error but I'm not sure.
Any assistance or advice would be most appreciated.
Regards,