search for: isnotzero

Displaying 1 result from an estimated 1 matches for "isnotzero".

Did you mean: isnonzero
2009 Dec 03
4
Replace values in a vector
Hi all, I have a vector like this: x<- c(0.7, 0.1, 0, 0.2, 0.2, 0, 0, 0 , 0, 0.4, 0, 0.8, 1.8) I would like to replace the zero values with the first previous non zero value. my returning vector should look like this: y<-c( 0.7, 0.1, 0.1,0.2,0.2,0.2,0.2,0.2, 0.4, 0.4, 0.8, 1.8) How can I do this in R without using for loop? Thank you