Fill with "Last Observation Carried Forward"
fill_locf(body, idx, fail = NA)
body |
The body of the vector. |
---|---|
idx |
the index to replace with. |
fail |
In case it fails to fill some values. |
Returns a vector with the same class and attributes as the input vector.
#> [1] NA NA 5 3 2# A not so very neat way to deal with NA when `fill_locf` fails is lagx(x, n = 2, fill = ~ fill_locf(.x,.y, fail = 0))#> [1] 0 0 5 3 2#> [1] 2 2 5 5 5#> [1] 5 5 5 3 2#> [1] 2 2 5 NA NA#> [1] 2 2 5 0 0