Reputation: 37
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
Upvotes: 3
Views: 807
Reputation: 46978
try relevel:
iris <- iris %>% mutate(Species=relevel(Species,ref="versicolor"))
Upvotes: 2