Skip to content

fill() should handle NaN #982

Closed
@ArtemSokolov

Description

@ArtemSokolov

Dear tidyverse developers,

In the current implementation, fill() ignores NaN. My current workaround has been a (rather strange-looking) use of replace_na() to replace NaN with NA before passing the values to fill():

X <- tibble::tibble(x = c(1,0,3,0),
                    y = c(2,0,2,0),
                    z = x/y)

tidyr::fill(X, z)
#  # A tibble: 4 x 3
#        x     y     z
#    <dbl> <dbl> <dbl>
#  1     1     2   0.5
#  2     0     0 NaN
#  3     3     2   1.5
#  4     0     0 NaN

tidyr::replace_na(X, list(z=NA)) %>%
    tidyr::fill(z)
# # A tibble: 4 x 3
 #       x     y     z
 #   <dbl> <dbl> <dbl>
 # 1     1     2   0.5
 # 2     0     0   0.5
 # 3     3     2   1.5
 # 4     0     0   1.5

I believe it would be warranted to have fill() treat NaN and NA equivalently, because 1) it is already done so by replace_na(), and 2) is.na(NaN) is TRUE.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions