Skip to content

Instantly share code, notes, and snippets.

@Lextuga007
Created December 31, 2020 11:13
Show Gist options
  • Select an option

  • Save Lextuga007/e5d8c0d6ddd64ec84a6e7e3039a18908 to your computer and use it in GitHub Desktop.

Select an option

Save Lextuga007/e5d8c0d6ddd64ec84a6e7e3039a18908 to your computer and use it in GitHub Desktop.
# create a tibble of month names (generated by copying over from Excel using {datapasta} :)
birthmonth <- tibble::tribble(
~month_full, ~month_short,
"January", "Jan",
"February", "Feb",
"March", "Mar",
"April", "Apr",
"May", "May",
"June", "Jun",
"July", "Jul",
"August", "Aug",
"September", "Sep",
"October", "Oct",
"November", "Nov",
"December", "Dec"
) %>%
mutate(month_full = factor(month_full, levels = month.name)) # this orders according to month name
# check levels are correct from last mutate
levels(birthmonth$month_full)
# generate a sample data frame
df <- data.frame(
birthmonth = sample(birthmonth$month_full, 100, replace = TRUE)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment