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. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello Faheem, On Wed, 14 Mar 2001, Faheem Mitha wrote:> > 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.Maybe this can give you a starting point. I guess their are more elegant ways to do this ...> clist <- function (liste, x) {+ + tmp <- paste("list(", + paste(paste("liste[[",1:length(liste),"]]",sep=""), + collapse=","),",x)",sep="") + eval(parse(text=tmp)) + }> > clist(xy,z)[[1]] [1] 0.6855152 0.5541156 [[2]] [1] 0.19300487 0.07686829 [[3]] [1] 0.4915225 0.9025518 best jan -- +----------------------------------- Jan Goebel (mailto:jgoebel at diw.de) DIW Berlin Longitudinal Data and Microanalysis K?nigin-Luise-Str. 5 D-14195 Berlin -- Germany -- phone: 49 30 89789-377 +----------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
try c(xy,list(z))> x <- runif(2) > y <- runif(2+ )> z <- runif(2) > xy <- list(x,y) > xyz <- list(x,y,z) > c(xy,list(z))[[1]] [1] 0.1194932 0.9874886 [[2]] [1] 0.5036242 0.7492557 [[3]] [1] 0.3930850 0.2587288> xyz[[1]] [1] 0.1194932 0.9874886 [[2]] [1] 0.5036242 0.7492557 [[3]] [1] 0.3930850 0.2587288 R. Woodrow Setzer, Jr. Phone: (919) 541-0128 Experimental Toxicology Division Fax: (919) 541-5394 Pharmacokinetics Branch NHEERL MD-74; US EPA; RTP, NC 27711 Faheem Mitha <faheem at email.unc.ed To: r-help at stat.math.ethz.ch u> cc: Sent by: Subject: [R] concatenating lists owner-r-help at stat.ma th.ethz.ch 03/14/01 06:17 PM 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. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._