Skip to content

fill() should handle NaN #982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ArtemSokolov opened this issue Jun 8, 2020 · 0 comments · Fixed by #1214
Closed

fill() should handle NaN #982

ArtemSokolov opened this issue Jun 8, 2020 · 0 comments · Fixed by #1214
Labels
feature a feature request or enhancement missing values 💀 vctrs ↗️

Comments

@ArtemSokolov
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement missing values 💀 vctrs ↗️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants