This a function to handle missing values in a dataframe column. It fills empty/missing rows values with the immediate available previous value.

LOCF(x)

Arguments

x

data series/vector with missing values to fill (vector)

Value

returns the same data series with missing values filled in with the preceding value

Examples

LOCF(c(1, 2, NA, 5, NA, 9, 10))
#> [,1] #> [1,] 1 #> [2,] 2 #> [3,] 2 #> [4,] 5 #> [5,] 5 #> [6,] 9 #> [7,] 10