-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Suppose I have this vector
x = c(NA,1,NA,NA,5,3,NA,NA)
and I want to fill NAs with the preceding non NA values. I can do this
nafill(x = c(NA,1,NA,NA,5,3,NA,NA), type = "locf")
[1] NA 1 1 1 5 3 3 3
Great, but sometimes I want to specify a fill value to catch the NA(s) at the front of the vector. I tried this which seemed obvious to me,
nafill(x = c(NA,1,NA,NA,5,3,NA,0), type = "locf", fill = -1)
but it didn't work and instead gave a warning, "argument 'fill' ignored, only make sense for type='const'".
My request is to extend the method so that 'fill' is applied to the front/back of the vector for types 'locf' and 'nocb' respectively. Thanks
Output of sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin18.5.0 (64-bit)
Running under: macOS Mojave 10.14.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /usr/local/Cellar/openblas/0.3.6/lib/libopenblasp-r0.3.6.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.12.3
loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0
jangorecki and MichaelChirico