+d <- merge(d, attendance.counts,
+ all.x=TRUE, all.y=TRUE,
+ by="discord.name")
+
+days.list <- lapply(unique(attendance$day), function (day) {
+ day.total <- table(call.list.full$day == day)[["TRUE"]]
+ lapply(d$discord.name, function (discord.name) {
+ num.present <- nrow(attendance[attendance$day == day & attendance$discord.name == discord.name,])
+ if (num.present/day.total > 1) {print(day)}
+ data.frame(discord.name=discord.name,
+ days.present=(num.present/day.total))
+ })
+})
+
+days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
+
+days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
+
+attendance.days <- data.frame(discord.name=names(days.tbl),
+ days.present=days.tbl,
+ days.absent=length(list.files(".", pattern="^attendance-.*tsv$"))-days.tbl)
+
+d <- merge(d, attendance.days,
+ all.x=TRUE, all.y=TRUE, by="discord.name")
+
+d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
+
+## make some visualizations of whose here/not here
+#######################################################
+
+png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
+
+ggplot(d) +
+ aes(x=as.factor(num.calls), fill=days.absent, group=days.absent) +
+ geom_bar(color="black") +
+ scale_x_discrete("Number of questions asked") +
+ scale_y_continuous("Number of students") +
+ scale_fill_continuous("Days absent", low="red", high="blue")+
+ theme_bw()
+
+dev.off()
+
+png("questions_absenses_boxplots.png", units="px", width=800, height=600)
+
+ggplot(data=d) +
+ aes(x=as.factor(num.calls), y=days.absent) +
+ geom_boxplot() +
+ scale_x_discrete("Number of questions asked") +
+ scale_y_continuous("Days absent")
+
+dev.off()