My question is certainly very basic, though I'm struggling to find a proper solution in this forum. I have a logical vector (v1) and numeric (v2) vector with different lengths. The length of v2 is equal to the sum of TRUE values in v1.
My goal is to create a third vector (v3), with the same number of elements as v1, assigning NA whenever v1 == FALSE and using the values in v2 to "populate" v3 when v1 == TRUE. Something like this:
v1 <- c( FALSE, TRUE, TRUE, FALSE, FALSE , TRUE )
v2 <- c(3, 0, 2)
Desired output (v3):
NA, 3, 0, NA, NA, 2
Thanks!