Skip to content

How to get to the varable in a list

1 message · Martin Henry H. Stevens

#
Hi Lisa,
Try the following -- there are probably better solutions, but these seem 
to work.
Hank Stevens
Miami University
Oxford, OH, USA

a <- vector("list",3)
names(a) <- 1:3
a[[1]] <- data.frame(x1=3,x2=1)
a[[2]] <- data.frame(x1=c(3,3),x2=c(2,2))

a[[3]] <- data.frame(x1=c(3,3), x2=c(3,3))
a

unlist(sapply(a, function(x) x$x1 ))
unlist(sapply(a, function(x) x[,1] ))
Lisa Wang wrote: