You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with factors a lot, so forcats is a very welcome new package to me; nice and easy-to-use functions for describing and visualizing factors. However, when manipulating factors for other types of use, I'm finding it difficult that NA is sometimes added as an additional factor level. E.g., I have a factor with multiple different codes for missingness that I'd like to convert into a numerical variable, combining all missing values into NA. After recoding of missing values, if I use fct_drop for dropping unused levels, it adds NA as a factor level, which is then given a number with as.numeric.
> my_factor <- factor(c(letters[1:4], NA, NA), levels = letters[1:6])
> my_factor
[1] a b c d <NA> <NA>
Levels: a b c d e f
> as.numeric(my_factor)
[1] 1 2 3 4 NA NA
> fct_drop(my_factor)
[1] a b c d <NA> <NA>
Levels: a b c d <NA>
> as.numeric(fct_drop(my_factor))
[1] 1 2 3 4 5 5
There's already the fct_explicit_na if you want to add missing values as a factor level, so would you consider removing the feature from fct_drop, or adding an argument for choosing either option?
If you like to keep drop_levels like this, then it would be better to change the description, as the functioning of droplevels and fct_drop are not the same in the case of missing values (the first has exclude = NA, and the latter exclude = NULL).
The text was updated successfully, but these errors were encountered:
I'm working with factors a lot, so forcats is a very welcome new package to me; nice and easy-to-use functions for describing and visualizing factors. However, when manipulating factors for other types of use, I'm finding it difficult that NA is sometimes added as an additional factor level. E.g., I have a factor with multiple different codes for missingness that I'd like to convert into a numerical variable, combining all missing values into NA. After recoding of missing values, if I use
fct_drop
for dropping unused levels, it adds NA as a factor level, which is then given a number withas.numeric
.There's already the
fct_explicit_na
if you want to add missing values as a factor level, so would you consider removing the feature fromfct_drop
, or adding an argument for choosing either option?If you like to keep
drop_levels
like this, then it would be better to change the description, as the functioning ofdroplevels
andfct_drop
are not the same in the case of missing values (the first hasexclude = NA
, and the latterexclude = NULL
).The text was updated successfully, but these errors were encountered: