Data i have
id <- c(1,1,1,2,2,3,3,4,4,4)
a <- c(NA,NA,1,5,2,NA,7,NA,NA,8)
b <- c(1,2,3,4,5,6,7,8,9,10)
df <- data.frame(id,a,b)
Data i want
a2 <- c(1,1,1,5,2,7,7,8,8,8)
df2 <- data.frame(id,a2,b)
I just want to fill NA's in "a" column with immediate next filled column of same id.
if many same id have many NA's at first and only one filled value at last row, fill all NA's with the filled value of the same id.(just like id 1 case in example)
Some one help me to do this.
Thank you