For a vector of uelements and a vector of iindices in a vector x, how can we insert elements uin xafter the elements corresponding to indices in i, without iterations?
for example
x <- c('a','b','c','d','e')
u <- c('X','X')
i <- c(2,3)
# now we want to get c('a','b','X','c','X','d','e')
I want to do this in one step (i.e. avoid loops), because each step requires the creation of a new vector, and in practice these are long vectors.
I hope for the magic of the index.
source
share