Re: [R] Interlacing two vectors

2003-08-20 Thread Richard A. O'Keefe
Murray Jorgensen <[EMAIL PROTECTED]> wrote: I want to interlace two vectors. How, precisely, do you want to do this? Here are two vectors x and y of the same length: x <- c(1,2,3) y <- c(4,5,6) The simplest way I can think of to interleave them is as.vector(rbind(x,y)) => 1 4

Re: [R] Interlacing two vectors

2003-08-20 Thread kjetil brinchmann halvorsen
On 21 Aug 2003 at 9:16, Murray Jorgensen wrote: Hola! I'm not sure if this is better, but if we can interlace first 1:n with (n+1):2n the rest is indexing: > x <- 1:10 > y <- 1:10 + 0.5 > interl <- function(n) { +res <- numeric(2*n) +for (j in 1:n) { + res[2*j-1] <- j +

Re: [R] Interlacing two vectors

2003-08-20 Thread Jerome Asselin
as.vector(rbind(x,z))or c(rbind(x,y)) saves you one step. Don't know if there's a better solution. HTH, Jerome On August 20, 2003 02:16 pm, Murray Jorgensen wrote: > I want to interlace two vectors. This I can do: > > x <- 1:4 > > z <- x+0.5 > > as.vector(t(cbind(x,z))) > > [1] 1.0 1

Re: [R] Interlacing two vectors

2003-08-20 Thread Peter Dalgaard BSA
Murray Jorgensen <[EMAIL PROTECTED]> writes: > I want to interlace two vectors. This I can do: > > > x <- 1:4 > > z <- x+0.5 > > as.vector(t(cbind(x,z))) > [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 > > but this seems rather inelegant. Any suggestions? Well, there's as.vector(rbind(x,z)) at least..

[R] Interlacing two vectors

2003-08-20 Thread Murray Jorgensen
I want to interlace two vectors. This I can do: > x <- 1:4 > z <- x+0.5 > as.vector(t(cbind(x,z))) [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 but this seems rather inelegant. Any suggestions? Murray -- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, Univ