Forward and backward fill data frame in R [duplicate]

We can do this with na.locf from zoo

library(zoo)
na.locf(na.locf(df1), fromLast = TRUE)
#  Col1 Col2
#1   20   10
#2   25   10
#3   15   10
#4   15   10
#5   15   15

Leave a Comment