In R, I have some class attendance data in a tidy data set. Here's a MWE:
library(lubridate)
students <- c("Alice", "Bob", "Alice", "Bob", "Alice", "Bob")
presences <- c("Present", "Present", "Present", "Absent", "Absent", "Present")
dates <- mdy(c("2/17/2020", "2/17/2020", "2/18/2020", "2/18/2020", "2/19/2020", "2/19/2020"))
df <- data.frame(Student=students,
Presence=presences,
Date=dates,
stringsAsFactors=FALSE)
which produces
df
Student Presence Date
1 Alice Present 2020-02-17
2 Bob Present 2020-02-17
3 Alice Present 2020-02-18
4 Bob Absent 2020-02-18
5 Alice Absent 2020-02-19
6 Bob Present 2020-02-19
For a report, I want to produce a spreadsheet-style table where the rows are by student, the columns are by date, and the cell values are presence status. I've typed up the expected output explicitly below.
02/17/20 02/18/20 02/19/20
Alice Present Present Absent
Bob Present Absent Present
How do I achieve this using R? I think my difficulty is that all the documentation I can find is for tidying data, and my goal here is essentialy to untidy it.