[R] combining two list objects

From: Rajarshi Guha <rxg218_at_psu.edu>
Date: Sat 10 Dec 2005 - 03:52:41 EST


Hi, I have 2 list objects, say list1 and list2

Each element of list1 is a list with components: model, pcorrect Each element of list2 has a single unnamed numeric value

What I would like to do is to be able to combine list1 and list2 to give list3 such that
list3 is a list where each element is a list with components:

model, pcorrect, tcorrect

where tcorrect is a value taken from list2.

I am currently doing something like below. Is it possible to do this without explicitly looping?

 ll1 <- list(model=1, pcorrect=2)
 ll2 <- list(model=3, pcorrect=4)

 list1 <- list(ll1, ll2)
 list2 <- list(9,10)

 list3 <- list()
 for (i in 1:length(list1)) {

    tmp1 <- list1[[i]]
    tmp2 <- list2[[i]]
    list3[[i]] <- list(model=tmp1$model, pcorrect=tmp1$pcorrect, tcorrect=tmp2)
 }

 > list3
[[1]]
[[1]]$model
[1] 1

[[1]]$pcorrect
[1] 2

[[1]]$tcorrect
[1] 9

[[2]]
[[2]]$model
[1] 3

[[2]]$pcorrect
[1] 4

[[2]]$tcorrect
[1] 10
    

Thanks,



Rajarshi Guha <rxg218_at_psu.edu> <http://jijo.cjb.net> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE

"whois awk?", sed Grep.

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Dec 10 03:57:38 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:35 EST