Hi I'm trying to reorder factor levels, by only defining which factor level should be first.
library(plyr)
library(dplyr)
wrong <-iris %>% mutate(Species = reorder(Species,desc(Species)))
levels(iris.re$Species)
I would like to use mutate to define f.e. versicolor to be the first factor level and sort the other factor levels.
I know there are other options to do this, but I would like to use plyr/dplyr.
Thanks
try relevel:
iris <- iris %>% mutate(Species=relevel(Species,ref="versicolor"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With