I have a vector in R,
a = c(2,3,4,9,10,2,4,19)
let us say I want to efficiently insert the following vectors, b, and c,
b =
The straightforward approach:
b.pos <- 3 d.pos <- 7 c(a[1:b.pos],b,a[(b.pos+1):d.pos],d,a[(d.pos+1):length(a)]) [1] 2 3 4 2 1 9 10 2 4 0 1 19
Note the importance of parenthesis for the boundaries of the : operator.
: