r - Filling NA values with repetition of the leftmost non-NA value in zoo -
how fill na values repetition of leftmost non-na value in zoo
?
in zoo pdf guide have function na.fill
performs task. question how function take leftmost non-na value?
below little example
> z <- zoo(c(na, 2, na, 1, 4, 5, 2, na)) > z 1 2 3 4 5 6 7 8 na 2 na 1 4 5 2 na > na.fill(z, "extend") 1 2 3 4 5 6 7 8 2.0 2.0 1.5 1.0 4.0 5.0 2.0 2.0 > na.fill(z, c("extend", na)) 1 2 3 4 5 6 7 8 2 2 na 1 4 5 2 2
the result want following:
1 2 3 4 5 6 7 8 na 2 2 1 4 5 2 2
library(zoo) z <- zoo(c(na, 2, na, 1, 4, 5, 2, na)) na.locf(z, na.rm = false) # 1 2 3 4 5 6 7 8 #na 2 2 1 4 5 2 2
Comments
Post a Comment