Check for a column in the list

I am trying to check if there is a column with all NA entries in the data frame in the list.

I tried this one lapply(df,function(x)all(is.na(df)))and worked great to check all the columns. How can I check if the first NA column is in the bottom list.

I tried lapply(df[,1],function(x)all(is.na(df[,1]))), but this is not the right way to do

[[1]]
             ID Mas5.SignalIntensity DetectionCalls     P.value
1     1007_s_at           3242.90209              P 0.000218932
2       1053_at            377.81481              P 0.017000453
3        117_at            114.88743              A 0.066864977
4        121_at           8739.03257              P 0.000218932


[[2]]
             ID Mas5.SignalIntensity DetectionCalls     P.value
1            NA            134.40764              P 0.000561751
2            NA            453.34875              P 0.002227740
3            NA            706.34996              A 0.066864977
4            NA            102.51459              A 0.089405078

[[3]]
             ID Mas5.SignalIntensity DetectionCalls     P.value
1     1007_s_at          7015.297075              P 0.000218932
2       1053_at           677.459859              P 0.011447358
3        117_at           180.568654              A 0.267462560
4        121_at          1693.426847              P 0.006531992
5     1255_g_at           181.221325              A 0.339557900
+4
source share
1 answer

Try

 sapply(lst, function(x) any(colSums(!is.na(x))==0))
 #[1]  TRUE FALSE  TRUE

Update

If you want to check a specific column, for example. column 2

sapply(lst, function(x) all(is.na(x[,2])))
#[1] FALSE FALSE  TRUE

or

sapply(lst, function(x) sum(!is.na(x[,2]))==0)
#[1] FALSE FALSE  TRUE

data

 df <- data.frame(col1= NA, col2=1:5, col3=c(1:3,NA, NA))
 df1 <- data.frame(col1=1:5, col2=6:10, col3=11:15)
 df2 <- data.frame(col1=c(NA,2), col2= NA, col3=c(2,4))
 lst <- list(df, df1, df2)
+4
source

All Articles