I have a dataframe with a column containing zero values:
a <- 1:10
b <- c(1, 0, 0, 0, 0, -1, -1, 0, 0, 1)
df <- data.frame(a, b)
df
How can I replace the zero values with the last non zero value ie column df$b to be:
1,-1,-1,-1,-1,-1,-1,1,1,1
Thank you for your help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…