[R] Extract elements from objects in a list
Jeremy Miles
jeremy.miles at gmail.com
Wed Jun 29 01:22:48 CEST 2011
Hi All,
I want to extract elements of elements in a list.
Here's an example of what I mean:
If I create a list:
x <- as.list(100)
for(loop in c(1:100)) {
x[[loop]] <- summary(runif(100))
}
> head(x)
[[1]]
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.02271 0.25260 0.58130 0.52120 0.77270 0.99670
[[2]]
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.006796 0.259700 0.528100 0.515500 0.781900 0.993100
[[3]]
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.00927 0.22800 0.40780 0.46410 0.69460 0.98780
I want to extract (say) the medians as a vector. This would be:
x[[1]][[3]]
x[[2]][[3]]
x[[3]][[3]]
I thought there would be a way of doing this with something like
apply(), but I cannot work it out. Is there a way of doing this
without a loop? Thanks,
Jeremy
More information about the R-help
mailing list