[R] Merge two vectors into one

arun smartpink111 at yahoo.com
Sun Mar 23 01:24:24 CET 2014


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 vector z as 1 4 2 5 3 6 

Thanks for your help 

Tham




More information about the R-help mailing list