I have a vector of zeros, such as length 10. So,
v = rep(0,10)
I want to fill in some values ββof a vector based on a set of indices in v1 and another vector v2 that actually has values ββin the sequence. So for another vector v1 the indices say
v1 = c(1,2,3,7,8,9)
and
v2 = c(0.1,0.3,0.4,0.5,0.1,0.9)
In the end i want
v = c(0.1,0.3,0.4,0,0,0,0.5,0.1,0.9,0)
So, the indices in v1 were mapped from v2, and the rest were equal to 0. I obviously can write a for loop, but this is too long in R due to the length of the actual matrices. Any easy way to do this?
source share