tidyverse / forcats

🐈🐈🐈🐈: tools for working with categorical variables (factors)
https://forcats.tidyverse.org/
Other
553 stars 126 forks source link

fct_relevel not working #351

Closed qutkat closed 1 year ago

qutkat commented 1 year ago

Hello,

I tried using the following code to reorder a variable. i didn't receive any error message but the factors were still printing out in alphabetical order instead of the order I specified.

test = dass %>% mutate(depression_rating = fct_relevel(depression_rating, "normal", "mild", "moderate", "severe", "extremely_severe"))

Thanks,

micwij commented 1 year ago

I think it should work if you wrap the new levels in a character vector:

test = dass %>% mutate(depression_rating = fct_relevel(depression_rating, c("normal", "mild", "moderate", "severe", "extremely_severe")))

qutkat commented 1 year ago

Thankyou this works!


From: Micha Wijesingha Ahchige @.> Sent: Thursday, 6 April 2023 7:19 PM To: tidyverse/forcats @.> Cc: Katherine Barlow @.>; Author @.> Subject: Re: [tidyverse/forcats] fct_relevel not working (Issue #351)

I think it should work if you wrap the new levels in a character vector:

test = dass %>% mutate(depression_rating = fct_relevel(depression_rating, c("normal", "mild", "moderate", "severe", "extremely_severe")))

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https://github.com/tidyverse/forcats/issues/351*issuecomment-1498748553__;Iw!!NVzLfOphnbDXSw!ANWqz6-0pwTzlC-1yHiGsn5Rw86eyjo4IvR2WK3vHpGMIa3yKEjbDAsPxO0C8M3HZKKHPzCYdM_WQF-mJMpzRmJYVpO1rmdS_urt$, or unsubscribehttps://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/A66LQF52JF4FHTWFRSP7KSTW72DCHANCNFSM6AAAAAAWSABXOY__;!!NVzLfOphnbDXSw!ANWqz6-0pwTzlC-1yHiGsn5Rw86eyjo4IvR2WK3vHpGMIa3yKEjbDAsPxO0C8M3HZKKHPzCYdM_WQF-mJMpzRmJYVpO1rpRdMekb$. You are receiving this because you authored the thread.Message ID: @.***>