I would like to get the values in column C
Column B indicates the changes in the value and I want to create column C based on how the value changes in B
I would like to get the values in column C
Column B indicates the changes in the value and I want to create column C based on how the value changes in B
We can try na.locf
(assuming that the blanks in 'B' are NA
after reading the excel file)
library(zoo)
df1$C <- na.locf(na.locf(df1$B, na.rm=FALSE), fromLast=TRUE)
df1$C
#[1] 20 20 20 20 30 30 30
Data:
df1 = structure(list(A = 1:7, B = c(NA, NA, 20, NA, NA, 30, NA)), .Names = c("A",
"B"), row.names = c(NA, -7L), class = "data.frame")