[R] construct a vector
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Wed Nov 26 14:39:09 CET 2008
axionator wrote:
> Hi all,
> I have an unkown number of vectors (>=2) all of the same length. Out
> of these, I want to construct a new one as follows:
> having vectors u,v and w, the resulting vector z should have entries:
> z[1] = u[1], z[2] = v[1], z[3] = w[1]
> z[4] = u[2], z[5] = v[2], z[6] = w[2]
> ...
> i.e. go through the vector u,v,w, take at each time the 1st, 2sd, ...
> elements and store them consecutively in z.
> Is there an efficient way in R to do this?
>
>
suppose you have your vectors collected into a list, say vs; then the
following will do:
as.vector(do.call(rbind, vs))
vQ
More information about the R-help
mailing list