"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)]".
> N
name
[1] "two"
[[1]][[2]]$vec
[1] 5 6 7 8
[[2]]
[[2]][[1]]
[[2]][[1]]$name
[1] "one"
[[2]][[1]]$vec
[1] 1 2 3 4
[[2]][[2]]
[[2]][[2]]$name
[1] "two"
[[2]][[2]]$vec
[1] 5 6 7 8
> -Original Message-
> From: Roger D. Peng [mailto:[EMAIL PROTECTED]
>
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:
as.vector(sap
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
[] 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, f
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