###########
# Attendance data is created by combining Course Instruction attendance data from LibInsights and Outreach Instruction attendance data from LibInsights. It can be filtered by columns such as date, year, month, instructor, and workshop topic.
###########
# Outreach
attendance_outreach <- read.csv("raw_data/attendance_outreach.csv",
header=TRUE,
stringsAsFactors=FALSE)
attendance_outreach$Is.Course <- "Not a course"
attendance_outreach$Requested.[is.na(attendance_outreach$Requested.)] <- "Unknown"
attendance_outreach$Requested.[attendance_outreach$Requested.==""] <- "Unknown"
# Courses
attendance_courses <- read.csv("raw_data/attendance_courses.csv",
header=TRUE,
stringsAsFactors=FALSE)
attendance_courses$Is.Course <- "Within a course"
attendance_courses$Requested. <- "Yes"
attendance_courses$Total.Attendees <- attendance_courses$Total.Attendance
###########
# We clean dates out by weekday, year, month, day, and times for later analysis and data subsetting.
###########
# Outreach
# Month, day, year, hour, minute, seconds
attendance_outreach$Event.Date.and.Time_2 <- ymd_hms(attendance_outreach$Event.Date.and.Time,
truncated = 3)
# separate year, month, date, times
attendance_outreach$year <- year(attendance_outreach$Event.Date.and.Time_2)
attendance_outreach$month <- month(attendance_outreach$Event.Date.and.Time_2)
attendance_outreach$day <- day(attendance_outreach$Event.Date.and.Time_2)
attendance_outreach$wday <- wday(attendance_outreach$Event.Date.and.Time_2,
week_start = 1, #1 = Monday,
label = TRUE # days of weeks as characters
)
attendance_outreach$hour <-as.numeric(
format(attendance_outreach$Event.Date.and.Time_2, "%H"))
attendance_outreach$Date <-
format.Date(attendance_outreach$Event.Date.and.Time_2, "%m/%d/%Y")
# convert 00 hour to NA
# attendance_outreach[attendance_outreach$hour==00, "hour"] <- NA
attendance_outreach$hour <- as.numeric(attendance_outreach$hour)
# Semester defined as spring (month 1-5), summer (month 6-7), fall (month 8-12)
attendance_outreach$Semester[attendance_outreach$month>0&
attendance_outreach$month<6] <- "Spring"
attendance_outreach$Semester[attendance_outreach$month>5&
attendance_outreach$month<8] <- "Summer"
attendance_outreach$Semester[attendance_outreach$month>7&
attendance_outreach$month<=12] <- "Fall"
# Courses
# Month, day, year, hour, minute, seconds
attendance_courses$Event.Date.and.Time_2 <-
ymd_hms(attendance_courses$Session.Date,
truncated = 3)
# separate year, month, date, times
attendance_courses$year <- year(attendance_courses$Event.Date.and.Time_2)
attendance_courses$month <- month(attendance_courses$Event.Date.and.Time_2)
attendance_courses$day <- day(attendance_courses$Event.Date.and.Time_2)
attendance_courses$wday <- wday(attendance_courses$Event.Date.and.Time_2,
week_start = 1, #1 = Monday,
label = TRUE # days of weeks as characters
)
attendance_courses$hour <-as.numeric(
format(attendance_courses$Event.Date.and.Time_2, "%H"))
attendance_courses$Date <-
format.Date(attendance_courses$Event.Date.and.Time_2, "%m/%d/%Y")
# convert 00 hour to NA
# attendance_courses[attendance_courses$hour==00, "hour"] <- NA
attendance_courses$hour <- as.numeric(attendance_courses$hour)
# Semester defined as spring (month 1-5), summer (month 6-7), fall (month 8-12)
attendance_courses$Semester[attendance_courses$month>0&
attendance_courses$month<6] <- "Spring"
attendance_courses$Semester[attendance_courses$month>5&
attendance_courses$month<8] <- "Summer"
attendance_courses$Semester[attendance_courses$month>7&
attendance_courses$month<=12] <- "Fall"
###########
# Join outreach and course datasets
###########
# using dplyr's bind_rows instead of cbind ensures all columns are kept, including those unique to each dataset
attendance_named <- dplyr::bind_rows(attendance_outreach,
attendance_courses)
###########
## attendance
attendance_named <- left_join(attendance_named,
topics_complete_variations_cleaned,
by = c("Name.of.Workshop" = "WorkshopNameVariations")) %>%
dplyr::filter(!is.na(id))