-1

I would like to get the values in column C

enter image description here

Column B indicates the changes in the value and I want to create column C based on how the value changes in B

Frank
  • 66,179
  • 8
  • 96
  • 180

1 Answers1

1

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")     
Frank
  • 66,179
  • 8
  • 96
  • 180
akrun
  • 874,273
  • 37
  • 540
  • 662