In particular I am interested in equivalents of
df.fillna(method='ffill')
and
df.fillna(method='bfill')
We can use na.locf
from zoo
library(zoo)
na.locf(df)
and for the second case,
na.locf(df, fromLast=TRUE)
set.seed(24)
df <- as.data.frame(matrix(sample(c(1:3, NA), 5*4, replace=TRUE), 5, 4))