I have two vectors of equal length and I would like to halve the values in the first one based on a criteria from the second. As a concrete example, let
V1 = 1:6 ; V2 = c(0,0,1,1,0,1)
I would like to divide every value in V1 by 2 which corresponds to a 1 in V2.
I know how to do this using a for loop but each vector has several hundred thousand elements so it seems like there should be a much faster method.
What I am really looking for is something like the apply function but only applied to selective elements.