I am working on an xts object that contains some 0s in one of the columns and I need to replace them with the last value different than 0 found in the sequence.
For example, I am simplifying here using a regular R vector:
v = c(1, 2, 3, 0, 0, 0)
I need to change all the 0s with the last value != 0 in the sequence, in this case 3. The resulting vector should be:
> v
[1] 1 2 3 3 3 3
How can I achieve this, possibly using transform() or another vector operation?
Set the zeros to
NAand usena.locf: