I need to replace the levels of a factor column in a dataframe. Using the iris dataset as an example, how would I replace any cells which contain virginic
iris
virginic
Using dlpyr::mutate and forcats::fct_recode:
dlpyr::mutate
forcats::fct_recode
library(dplyr) library(forcats) iris <- iris %>% mutate(Species = fct_recode(Species, "Virginica" = "virginica", "Versicolor" = "versicolor" )) iris %>% count(Species) # A tibble: 3 x 2 Species n 1 setosa 50 2 Versicolor 50 3 Virginica 50