Question: basic R question: concatenate two numeric vectors grouped by element index

0

Johannes Rainer •

**1.4k**wrote:dear all!

So basically what I have are two numerical vectors:

A <- c( 1, 2, 3, 4, 6, 7 ) B <- c( 8, 9, 10, 11, 12, 13 )

and I would like to combine them so that the result would be:

1, 8, 2, 9, 3, 10, 4, 11, 6, 12, 7, 13

i.e. that the first element of B is next to the first of A and so on.

One way to do that is using `paste`

, but that's really not nice coding...

as.numeric( unlist( strsplit( paste( A, B, sep=":" ), split=":" ) ) ) [1] 1 8 2 9 3 10 4 11 6 12 7 13

is there any other, better way to achieve the same.

thanks in advance!

jo

ADD COMMENT
• link
•
modified 4.1 years ago
by
Axel Klenk •

**920**• written 4.1 years ago by Johannes Rainer •**1.4k**