r - Check if a column is na in a list -
i trying check if of data frame in list has column entries na.
i tried lapply(df,function(x)all(is.na(df)))
, works fine check columns. how can check if in below list, first column na.
i tried lapply(df[,1],function(x)all(is.na(df[,1])))
not correct way 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 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 0.066864977 4 na 102.51459 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 0.267462560 4 121_at 1693.426847 p 0.006531992 5 1255_g_at 181.221325 0.339557900
try
sapply(lst, function(x) any(colsums(!is.na(x))==0)) #[1] true false true
update
if want check particular column, e.g. 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)
Comments
Post a Comment