Grothendieck
Sent: Monday, March 06, 2006 12:12 AM
To: Ajay Narottam Shah
Cc: R-help
Subject: Re: [R] Interleaving elements of two vectors?
Try this (note that your x and y do not have the same length
and in this case the expression will recycle the shorter one
and give a warning):
z - c(rbind(x
Suppose one has
x - c(1, 2, 7, 9, 14)
y - c(71, 72, 77)
How would one write an R function which alternates between elements of
one vector and the next? In other words, one wants
z - c(x[1], y[1], x[2], y[2], x[3], y[3], x[4], y[4], x[5], y[5])
I couldn't think of a
Try this (note that your x and y do not have the same length
and in this case the expression will recycle the shorter one
and give a warning):
z - c(rbind(x, y))
On 3/5/06, Ajay Narottam Shah [EMAIL PROTECTED] wrote:
Suppose one has
x - c(1, 2, 7, 9, 14)
y - c(71, 72, 77)
You don't have y[4] But if you did, as.vector(rbind(x, y))
On Mon, 6 Mar 2006, Ajay Narottam Shah wrote:
Suppose one has
x - c(1, 2, 7, 9, 14)
y - c(71, 72, 77)
How would one write an R function which alternates between elements of
one vector and the next? In other