I aim to insert multiple elements to a vector each in different locations. This is the example followed by a number of trials which do not work.
w <- c( 1,3,2,4,2,3,2,4,5,7,9,3,2,4,2,5,7,4,2 )
u <- c( 3,7,9,12 )
o <- c( 10 , 20 , 30 , 40 )
I have tried:
append ( w , o , after = u )
# which adds the series one time in the first location of after
fun <- function (x) append ( w , o[[x]] , after = u[[x]] )
lapply ( seq ( length ( u )) , fun )
# which adds one element to the list each time for a new vector producing a number of vectors
for (i in length(o)) {
append ( w , o[[i]] , after = u[[i]] )
}
# which basically does nothing
Desired Output
1,3,2,10,4,2,3,2,20,4,5,30,7,9,3,40,2,4,2,5,7,4,2
Is there a way to insert each element one at a time in each specific location? I have seen several questions addressing the append basic for a single element with one location or two elements to be added to the same position however not multiple elements to be added to multiple locations in a vector.
See Question&Answers more detail:
os