Re: [R] Merge two vectors into one

2014-03-24 Thread Frans Marcelissen
Why not simply a-1:3 b-4:5 c(a,b) [1] 1 2 3 4 5 2014-03-22 23:22 GMT+01:00 Tham Tran hanhtham.t...@yahoo.com.vn: Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a single vector z as 1 4 2 5 3 6 Thanks for your help Tham -- View this

Re: [R] Merge two vectors into one

2014-03-24 Thread Lisa S
He wants a[1] b[1] a[2] b[2] a[3] b[3] I think you can do: x = as.vector(rbind(a, b)) On Mon, Mar 24, 2014 at 2:39 PM, Frans Marcelissen fransiepansiekever...@gmail.com wrote: Why not simply a-1:3 b-4:5 c(a,b) [1] 1 2 3 4 5 2014-03-22 23:22 GMT+01:00 Tham Tran

Re: [R] Merge two vectors into one

2014-03-24 Thread David Winsemius
On Mar 22, 2014, at 3:22 PM, Tham Tran wrote: Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a single vector z as 1 4 2 5 3 6 Thanks for your help Searching Stackoverflow for [r] interleave produced this idea fron @Arun, which I think is

Re: [R] Merge two vectors into one

2014-03-24 Thread Greg Snow
Just to satisfy my curiosity: library(microbenchmark) a - 1:10 b - 101:110 microbenchmark( + m1=as.vector( rbind(a,b) ), + m2=c( rbind(a,b) ), + m3=as.vector( matrix(c(a,b), nrow=2, byrow=TRUE) ), + m4={x - integer(length(a)*2); x[c(TRUE,FALSE)] - a; x[c(FALSE,TRUE)] - b; x}, + m5={x -

Re: [R] Merge two vectors into one

2014-03-24 Thread Tham Tran
Many thank for all your answers. it has helped me save time -- View this message in context: http://r.789695.n4.nabble.com/Merge-two-vectors-into-one-tp4687361p4687447.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Merge two vectors into one

2014-03-23 Thread David Winsemius
On Mar 22, 2014, at 3:22 PM, Tham Tran wrote: Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a single vector z as 1 4 2 5 3 6 One way: c( matrix(c(a,b), nrow=2, byrow=TRUE) ) Leaving in the usual footer because Nabble's interface usually omits

Re: [R] Merge two vectors into one

2014-03-23 Thread Rolf Turner
On 24/03/14 08:37, David Winsemius wrote: On Mar 22, 2014, at 3:22 PM, Tham Tran wrote: Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a single vector z as 1 4 2 5 3 6 One way: c( matrix(c(a,b), nrow=2, byrow=TRUE) ) It is more perspicuous to use

[R] Merge two vectors into one

2014-03-22 Thread Tham Tran
Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a single vector z as 1 4 2 5 3 6 Thanks for your help Tham -- View this message in context: http://r.789695.n4.nabble.com/Merge-two-vectors-into-one-tp4687361.html Sent from the R help mailing list archive

Re: [R] Merge two vectors into one

2014-03-22 Thread arun
Hi, May be this helps: a - 1:3  b - 4:6  z - as.vector(rbind(a,b))  z #[1] 1 4 2 5 3 6 #or z1 - setNames(c(a,b),rep(seq_along(a),2)) z1 - as.vector(z1[order(names(z1))]) z1 #[1] 1 4 2 5 3 6 A.K. Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a single

[R] Merge two vectors into one.

2009-01-28 Thread patricia garcía gonzález
Hi all, I have two vectors like this: x - c( Y, H, NA, NA ) y - c( NA, H, NA, B ) And would like to make one vector with the common elements, and the element available only in one of the vectors. res - c( Y, H, NA, B ) Thanks, Patricia From:

Re: [R] Merge two vectors into one.

2009-01-28 Thread patricia garcía gonzález
Hi, Sorry, the answers are yes yes yes. And thank you for your idea it works perfectly. Regards Patricia Date: Wed, 28 Jan 2009 16:01:11 +0100 Subject: Re: [R] Merge two vectors into one. From: csa...@rmki.kfki.hu To: kurtney...@hotmail.com CC: r-help@r-project.org

Re: [R] Merge two vectors into one.

2009-01-28 Thread Gábor Csárdi
Is position important? The vectors always have the same length? They always have the same entry if both are not NA? If yes, yes and yes, then res - ifelse( is.na(x), y, x) does what you want. Otherwise please explain better what you want. Gabor On Wed, Jan 28, 2009 at 3:54 PM, patricia garcía

Re: [R] Merge two vectors into one.

2009-01-28 Thread Dimitris Rizopoulos
you could start by something like the following: x - c(Y, H, NA, NA) y - c(NA, H, NA, B) ifelse(is.na(x), y, x) I hope it helps. Best, Dimitris patricia garcía gonzález wrote: Hi all, I have two vectors like this: x - c( Y, H, NA, NA ) y - c( NA, H, NA, B ) And would