Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- set.seed(1234)
- data <- c("10th Std. Pass", "11th Std. Pass", "12th Std. Pass", "5th Std. Pass",
- "6th Std. Pass", "Diploma / certificate course", "Graduate", "No Education")
- education <- factor(sample(data, size = 5, replace = TRUE),
- levels = c(data, "Data not available"))
- survey <- tibble(education)
- recoded_s <- survey %>% mutate(education =
- fct_collapse(education,
- "None" = "No Education",
- "Primary" = c("5th Std. Pass", "6th Std. Pass"),
- "Secondary" = c("10th Std. Pass", "11th Std. Pass", "12th Std. Pass"),
- "Tertiary" = c("Diploma / certificate course", "Graduate")
- ))
- recoded_s$education
- #> [1] Secondary Primary Primary Primary Tertiary
- #> Levels: Secondary Primary Tertiary None Data not available
- # Re-ordering and dropping variables
- factor(recoded_s$education, levels = c("None", "Primary", "Secondary", "Tertiary"))
- #> [1] Secondary Primary Primary Primary Tertiary
- #> Levels: None Primary Secondary Tertiary
Add Comment
Please, Sign In to add comment