Skip to content

Make discretize more consistent when supplied missing values#986

Merged
topepo merged 7 commits intomainfrom
fix-982
May 24, 2022
Merged

Make discretize more consistent when supplied missing values#986
topepo merged 7 commits intomainfrom
fix-982

Conversation

@EmilHvitfeldt
Copy link
Copy Markdown
Member

This PR aims to close #982 .

It makes it so discretize() will automatically remove missing values is keep_na = TRUE. It further updates some existing code to use call2(), modify_call() and eval_tidy().

library(modeldata)
library(recipes)
data(biomass)

biomass$carbon[1] = NA
summary(biomass$carbon)
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
#>   14.61   44.70   47.10   48.29   49.70   97.18       1

discretize(biomass$carbon, keep_na = TRUE)
#> Bins: 5 (includes missing category)
#> Breaks: -Inf, 44.7, 47.1, 49.7, Inf

discretize(biomass$carbon, keep_na = FALSE)
#> Error in quantile.default(x = c(NA, 49.5, 47.82, 45.1, 46.76, 45.4, 47.17, : missing values and NaN's not allowed if 'na.rm' is FALSE

discretize(biomass$carbon, keep_na = FALSE, na.rm = TRUE)
#> Bins: 4
#> Breaks: -Inf, 44.7, 47.1, 49.7, Inf

Created on 2022-05-20 by the reprex package (v2.0.1)

@EmilHvitfeldt EmilHvitfeldt requested review from topepo and removed request for topepo May 20, 2022 16:43
@EmilHvitfeldt EmilHvitfeldt marked this pull request as ready for review May 20, 2022 18:02
@EmilHvitfeldt EmilHvitfeldt requested a review from topepo May 20, 2022 18:02
Copy link
Copy Markdown
Member

@topepo topepo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good but please update the news file

@topepo topepo merged commit 2a19e12 into main May 24, 2022
@topepo topepo deleted the fix-982 branch May 24, 2022 22:06
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 8, 2022

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions Bot locked and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

discretize( ..., keep_na = T) does not work when there's NA (related to issue #127)

2 participants