I have a problem to subset my list containing data frames by simple condition - number of columns.
here is my dataset:
d1<-data.frame(a=rnorm(5), b=c(rep(2006, times=4),NA), cc=c(1:5))
d2<-data.frame(a=1:5, b=c(2007, 2007, NA, NA, 2007))
my list:
ls1<-list(d1, d2)
How can I subset data frames from ls1
which contain exactly 3 columns?
I tried this
lapply(ls1, subset, ncol = 3)
but it doesn't work.. thanks !!
ls1[sapply(ls1,ncol) == 3]
or
Filter(function(x) ncol(x) == 3, ls1)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments