Message-ID: <tenqitkrlmgj109shu0ceeasoeb2evt85d@4ax.com>
Date: 2001-06-18T01:50:40Z
From: Duncan Murdoch
Subject: extraction from a list of vectors
In-Reply-To: <1BDB01B13696D411BD6200D0B7C854EA22F9D9@chi-prd-mail1.xcaliber.com>
On Sun, 17 Jun 2001 17:10:26 -0500, you wrote:
> Hi ,
> I know this should be easy, but I haven't figured out a fast way to
>do it.
> I have a list of vectors: mylist <- list(vector1, vector2, ...,
>vectorN).
> (The vectors are made of integers. They vary in length from about 1
>to 10).
> I also have a vector of indices: myidx <- c( i1, i2, ..., iN).
> From these I'd like to make this: newvector <- c(vector1[i1],
>vector2[i2], ..., vectorN[iN]).
I don't know if this is fast or not, but I think it gives the result
you want:
unlist(sapply(myidx,function(x) mylist[[x]]))
Duncan Murdoch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._