df <- data.frame(
date = c("10/27/2025","10/28/2025","10/29/2025"),
Northampton_AQI = c(16, 12, 9),
Easthampton_AQI = c(19, 13, 9),
Hatfield_AQI = c(17, 12, 9)
)
dfSDS 192: Introduction to Data Science
What variables are displayed on this plot?
pivot_longer() to pivot a datasets from wider to longer format:pivot_longer() takes the following arguments:cols =: Identify a series of columns to pivot - The names of those columns will become repeated rows in the pivoted data frame, and the values in those columns will be stored in a new column.names_to =: Identify a name for the column where the column names will be storevalues_to =: Identify a name for the column were the values associated with those names will be storedNote: I use this far less often than
pivot_longer()
pivot_wider() to pivot a datasets from longer to wider format:pivot_wider() takes the following arguments:names_from =: Identify the column to get the new column names fromvalues_from =: Identify the column to get the cell values fromseparate() to split a column into multiple columns:separate() takes the following arguments:col: Identify the existing column to separateinto = c(): Identify the names of the new columnssep =: Identify the characters or numeric position that indicate where to separate columnsunit() to join multiple columns into one column:unite takes the following arguments:...: Identify the existing columns to unitecol: Name of the new columnsep =: Identify the characters or numeric position that indicate where to separate columns