r - Combine two equal length vectors alternating -


this question has answer here:

im struggling feel there must vectorized way not finding it. have 2 equal length vectors , combine them want first element in vector 1 followed first element in vector 2, second element in vector 1 followed second element in vector 2, etc.

vector1 <- c(301l, 50l, 61l, 84l, 90l) vector2 <- c(302l, 51l, 62l, 85l, 91l) 

what want result (i know combine them , use sort want keep order of them intact (301 & 302 come before rest).

vector3 <- c(301l, 302l, 50l, 51l, 61l, 62l, 84l, 85l, 90l, 91l) 

try

c(rbind(vector1, vector2)) 

or using map

unlist(map(c, vector1, vector2)) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -