0

How can I concatenate two vectors to get a vector with values alternatively from the first and second one?

Input

a<- c(1,2,3)
b<- c(4,5,6)

Output

c(1,4,2,5,3,6)
Fimba
  • 143
  • 3

1 Answers1

1

This is one way

> as.numeric(t(matrix(c(a,b), ncol = 2)))
[1] 1 4 2 5 3 6
Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453