2

In particular I am interested in equivalents of

df.fillna(method='ffill')

and

df.fillna(method='bfill')
user7188934
  • 1,021
  • 3
  • 11
  • 17

1 Answers1

3

We can use na.locf from zoo

library(zoo)
na.locf(df)

and for the second case,

na.locf(df, fromLast=TRUE)

data

set.seed(24)
df <- as.data.frame(matrix(sample(c(1:3, NA), 5*4, replace=TRUE), 5, 4))
akrun
  • 874,273
  • 37
  • 540
  • 662