library(tidyverse) library(rcis) theme_set(theme_minimal()) Run the code below in your console to download this exercise as a set of R scripts.
usethis::use_course("cis-ds/data-wrangling-relational-data-and-factors") # load the data data("gun_deaths") gun_deaths ## # A tibble: 100,798 × 10 ## id year month intent police sex age race place educa…¹ ## <dbl> <dbl> <chr> <chr> <dbl> <chr> <dbl> <chr> <chr> <fct> ## 1 1 2012 Jan Suicide 0 M 34 Asian/Pacifi… Home BA+ ## 2 2 2012 Jan Suicide 0 F 21 White Stre… Some c… ## 3 3 2012 Jan Suicide 0 M 60 White Othe… BA+ ## 4 4 2012 Feb Suicide 0 M 64 White Home BA+ ## 5 5 2012 Feb Suicide 0 M 31 White Othe… HS/GED ## 6 6 2012 Feb Suicide 0 M 17 Native Ameri… Home Less t… ## 7 7 2012 Feb Undetermined 0 M 48 White Home HS/GED ## 8 8 2012 Mar Suicide 0 M 41 Native Ameri… Home HS/GED ## 9 9 2012 Feb Accidental 0 M 50 White Othe… Some c… ## 10 10 2012 Feb Suicide 0 M NA Black Home <NA> ## # … with 100,788 more rows, and abbreviated variable name ¹education Convert month into a factor column Click for the solution # create a character vector with all month values month_levels <- c( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ) # or use the built-in constant month.