[R] construct a vector

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Wed Nov 26 14:38:23 CET 2008


> 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?

u <- 1:5
v <- (1:5) + 0.1
w <- (1:5) + 0.2
as.vector(rbind(u,v,w))
# [1] 1.0 1.1 1.2 2.0 2.1 2.2 3.0 3.1 3.2 4.0 4.1 4.2 5.0 5.1 5.2

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list