Hello, can anyone answer: Is there a fast, vectorized way to convert a list of integer vectors, in which each vector has different length, to a single vector that is simply the concatenation of all the member vectors? Or does one have to loop over the list and concatenate everything? -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> -----Original Message----- > From: owner-r-help at stat.math.ethz.ch [mailto:owner-r- > help at stat.math.ethz.ch] On Behalf Of Kevin Karty > Sent: Wednesday, September 25, 2002 7:44 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Lists to vectors... > > > > Hello, can anyone answer: > > Is there a fast, vectorized way to convert a list of integer vectors,in> which each vector has different length, to a single vector that is > simply the concatenation of all the member vectors? Or does one haveto> loop over the list and concatenate everything?If your list is "x": How about unlist(x, recursive = TRUE) See ?unlist Marc -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> Is there a fast, vectorized way to convert a list of integer vectors, in > which each vector has different length, to a single vector that is > simply the concatenation of all the member vectors? Or does one have to > loop over the list and concatenate everything?You may try function unlist, which flattens a list to a vector. Jun -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> test <- list(1:3, 5:9, 3:7) > test[[1]] [1] 1 2 3 [[2]] [1] 5 6 7 8 9 [[3]] [1] 3 4 5 6 7> do.call("c", test)[1] 1 2 3 5 6 7 8 9 3 4 5 6 7 Kjetil Halvorsen Kevin Karty wrote:> > Hello, can anyone answer: > > Is there a fast, vectorized way to convert a list of integer vectors, in > which each vector has different length, to a single vector that is > simply the concatenation of all the member vectors? Or does one have to > loop over the list and concatenate everything? > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
or even> unlist(list(1:3, 5:9, 3:7))[1] 1 2 3 5 6 7 8 9 3 4 5 6 7 Best, Renaud kjetil halvorsen wrote:> > > test <- list(1:3, 5:9, 3:7) > > test > [[1]] > [1] 1 2 3 > > [[2]] > [1] 5 6 7 8 9 > > [[3]] > [1] 3 4 5 6 7 > > > do.call("c", test) > [1] 1 2 3 5 6 7 8 9 3 4 5 6 7 > > Kjetil Halvorsen > > Kevin Karty wrote: > > > > Hello, can anyone answer: > > > > Is there a fast, vectorized way to convert a list of integer vectors, in > > which each vector has different length, to a single vector that is > > simply the concatenation of all the member vectors? Or does one have to > > loop over the list and concatenate everything? > > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- Dr Renaud Lancelot, v?t?rinaire CIRAD, D?partement Elevage et M?decine V?t?rinaire (CIRAD-Emvt) Programme Productions Animales http://www.cirad.fr/presentation/programmes/prod-ani.shtml (Fran?ais) http://www.cirad.fr/presentation/en/program-eng/prod-ani.shtml (English) ISRA-LNERV tel +221 832 49 02 BP 2057 Dakar-Hann fax +221 821 18 79 (CIRAD) Senegal e-mail renaud.lancelot at cirad.fr -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._