-
Notifications
You must be signed in to change notification settings - Fork 127
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
Feature request: argument in fct_recode to reorder based on sequence #45
Comments
Does |
Just ran into the same issue. I've got some data with nonsensically named classes and want to impose both new names and a sensible order at the same time. Since google led me here ... could you briefly explain a good way to do that? I.e. have a |
In answer to myself: fct_reorg <- function(fac, ...) {
fct_recode(fct_relevel(fac, ...), ...)
} Works like this:
|
I ran into this same question recently. relevel = c(
"Alfa" = "A",
"Bravo" = "B",
"Charlie" = "C",
"Delta" = "D")
after <- before %>%
mutate(
Var1 = fct_recode(fct_relevel(Var1, !!!relevel), !!!relevel),
Var2 = fct_recode(fct_relevel(Var2, !!!relevel), !!!relevel)) |
I struggled with making a clear title of this feature request, but here is my idea. I really like using the
fct_recode
function to change the levels of factors (especially for plotting purposes) but I noticed that the new version of the factor keeps the same order of levels as the original version before the recoding usingfct_recode
even though I specified the order different in the arguments tofct_recode
. It would be nice to have an extra parameter infct_recode
to let the order be dictated by how the levels are given in the call. Here's a minimal example using the forcats CRAN release of0.1.1
:The text was updated successfully, but these errors were encountered: