parse_factor implicitly relevels empty string "" and actual NA to factor "NA" #864
Labels
Comments
Thanks, should now be fixed! library(readr)
x <- c("", "NC", "NC", "NC", "", "", "NB", "NA")
tibble::as_tibble(parse_factor(x, levels = c("NA", "NB", "NC", ""), na = character()))
#> # A tibble: 8 x 1
#> value
#> <fct>
#> 1 ""
#> 2 NC
#> 3 NC
#> 4 NC
#> 5 ""
#> 6 ""
#> 7 NB
#> 8 NA Created on 2018-11-14 by the reprex package (v0.2.1) |
Awesome, thank you for your work! |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
readr_1.1.1
andtidyverse_1.2.1
I want to convert a string column to factors, taking
"NA"
as an actual factor level (say"NA"
means "North America"), and also taking""
as an actual factor level. However, both""
and<NA>
are mapped to"NA"
byparse_factor
, whileNC
is mapped to<NA>
.But I expected
The text was updated successfully, but these errors were encountered: