Skip to content

Should nafill replace NaN values? #4020

@ToeKneeFan

Description

@ToeKneeFan

This is more of a question than a feature request. The majority of answers to the SO question "Fastest way to replace NAs in a large data.table" use approaches that replace both NA and NaN, since is.na(NaN) is true. However, nafill and setnafill at the moment do not replace NaN values. Should these new functions be expected to fill NaN values as well?

# Minimal reproducible example

library(data.table)

x <- c(NA, NaN, 0, 1, 2)
y <- x

# using is.na to replace
y[is.na(y)] <- 0
print(y)
# [1] 0 0 0 1 2

# using nafill to replace
nafill(x, fill = 0)
# [1]   0 NaN   0   1   2

# Output of sessionInfo()

R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.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.6

loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0    knitr_1.25     xfun_0.10  

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions