Aren't sapply()/lapply() sufficient for this?
sapply(alist, function(x) x$vec)
[,1] [,2]
[1,]15
[2,]26
[3,]37
[4,]48
lapply(alist, function(x) x$vec)
[[1]]
[1] 1 2 3 4
[[2]]
[1] 5 6 7 8
HTH,
Andy
From: Waichler, Scott R
For a long time I've wanted a
[] works on a list and extracts multiple elements. However, that is not
it seems what you want, rather, unions of elements of elements of lists.
That is a pretty unusual need, and perhaps you could explain you you need
it.
Andy's solution still need something like
do.call(c, lapply(alist,
For the first case, I actually do this pretty often and usually use
something like:
as.vector(sapply(alist, [[, vec))
For the second case, I think you just need to use lapply():
alist - lapply(seq(along = alist), function(i)
alist[[i]]$name - new.names[i])
-roger
Waichler,
Sorry, that second example should be
alist - lapply(seq(along = alist), function(i) {
alist[[i]]$name - new.names[i])
alist
})
-roger
Roger D. Peng wrote:
For the first case, I actually do this pretty often and usually use
something like:
]]
[[2]][[2]]$name
[1] two
[[2]][[2]]$vec
[1] 5 6 7 8
-Original Message-
From: Roger D. Peng [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 15, 2004 12:24 PM
To: Waichler, Scott R
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Extracting multiple elements from a list
Sorry
Waichler, Scott R wrote:
Brian described well the operation I would like to do.
I'm not familiar with do.call() but I'll work on that.
Yes, ideally I would like to access values throughout a list object
with fully implict indexing, such as the invalid alist[[1:2]]$vec[c(2, 4)].
Notice I