Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge 2 vectors alternating indexes?

Tags:

merge

r

vector

I would like to merge 2 vectors this way :

a = c(1,2,3) b = c(11,12,13) merged vector : c(1,11,2,12,3,13) 

How could I do it ?

like image 427
Wicelo Avatar asked Sep 21 '14 17:09

Wicelo


Video Answer


1 Answers

This will work using rbind :

c(rbind(a, b)) 

For example:

a = c(1,2,3) b = c(11,12,13)  c(rbind(a,b))  #[1]  1 11  2 12  3 13  
like image 178
jalapic Avatar answered Oct 09 '22 11:10

jalapic