opensubscriber
   Find in this group all groups
 
Unknown more information…

r : r-help@stat.math.ethz.ch 6 March 2006 • 10:14AM -0500

[R] Interleaving elements of two vectors?
by Ajay Narottam Shah

REPLY TO AUTHOR
 
REPLY TO GROUP




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 clever and general way to write this. I am aware
of gdata::interleave() but it deals with interleaving rows of a data
frame, not elems of vectors.

--
Ajay Shah                                      http://www.mayin.org/ajayshah  
ajayshah@mayi...                             http://ajayshahblog.blogspot.com
<*(:-? - wizard who doesn't know the answer.

______________________________________________
R-help@stat... mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.