[R] concatenating lists

Faheem Mitha
Wed, 14 Mar 2001 23:17:39 -0000

Dear People,

I have been trying to perform concatenation operations on lists without
success. Consider the following example.

> x <- runif(2)
> y <- runif(2)
> z <- runif(2)
> xy <- list(x,y)
> xyz <- list(x,y,z)

I want to have a function foo such that foo(xy,z) is the same as xyz. This
appears not to be as easy as I thought, though there must be a way.
For example list(xy,z) gives

> list(xy,z)
[[1]]
[[1]][[1]]
[1] 0.6375946 0.1863654

[[1]][[2]]
[1] 0.7395102 0.7528323


[[2]]
[1] 0.5260601 0.8470781

and c(xy,z) gives

> c(xy,z)
[[1]]
[1] 0.6375946 0.1863654

[[2]]
[1] 0.7395102 0.7528323

[[3]]
[1] 0.5260601

[[4]]
[1] 0.847078

>

but

> xyz
[[1]]
[1] 0.6375946 0.1863654

[[2]]
[1] 0.7395102 0.7528323

[[3]]
[1] 0.5260601 0.8470781

Unlisting things doesn't seem to help either. I have been fiddling around
for a bit, and have done everything I can think of. Any suggestions?
Thanks in advance.

                             Sincerely, Faheem Mitha.