Lab 10: Factors and Dates
Reshape a factor, then parse the WMATA ridership dates.
Work in a Quarto document. Do 10.1
and 10.2 first. Put wmata_ridership.csv in
a data/ folder of your project (see the Data section of the
course page).
library(tidyverse)
library(lubridate)
1. Factors
fc <- factor(c("D","C","C","A","A","C","D","A","C","C","A","A","C","A","C","B","C","A","C","B"))
- Add level
"E"without adding any observations. - Bar chart of
fcby frequency, most frequent on the right. - Put the levels in reverse alphabetical order.
- Remove the observations that are
"C", then drop the unused level. - Collapse
"A"and"B"into"z".
2. Dates
Use data/wmata_ridership.csv.
- Parse
Date. Addyear,month, andwdaycolumns withlabel = TRUEwhere it applies. - Drop 2004.
- Boxplot of daily
Totalby weekday. - How long is the span as a duration and as an interval?