I am trying to clear some data and would like to replace zeros with values ββfrom the previous date. I was hoping the following code works, but it doesn't
temp = c(1,2,4,5,0,0,6,7)
temp[which(temp==0)]=temp[which(temp==0)-1]
returns
1 2 4 5 5 0 6 7
instead
1 2 4 5 5 5 6 7
What I was hoping for. Is there a good way to do this without a loop?
source
share