Skip to content

Commit

Permalink
updated fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Jun 5, 2024
1 parent cb03b09 commit 18283e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions R/standalone-forcats.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ fct_expand <- function(f, ..., after = Inf) {
}

fct_na_value_to_level <- function(f, level = NA) {
if (is.na(level)) {
# Use addNA to add NA as a level
f <- addNA(f)
} else {
# Convert NA to the specified level
f[is.na(f)] <- level
}
return(f)
if (!inherits(f, "factor")) f <- factor(f)

# make NA an explicit level
f <- addNA(f, ifany = FALSE)

# replace NA level with the string passed in `level` argument
if (!is.na(level)) levels(f)[is.na(levels(f))] <- level

f
}


Expand Down
2 changes: 1 addition & 1 deletion man/lst_scripts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 18283e4

Please sign in to comment.