3 gs <- read.delim("student_information.tsv")
5 colnames(d) <- c("student.num", "discord.name")
7 call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x)[,1:3]}))
8 colnames(call.list) <- gsub("_", ".", colnames(call.list))
10 call.list$day <- as.Date(call.list$timestamp)
12 call.counts <- data.frame(table(call.list$discord.name))
13 colnames(call.counts) <- c("discord.name", "num.calls")
15 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
17 ## set anything that's missing to zero
18 d$num.calls[is.na(d$num.calls)] <- 0
20 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
23 file.to.attendance.list <- function (x) {
25 d.out <- data.frame(discord.name=unlist(strsplit(tmp[[2]], ",")))
26 d.out$day <- rep(as.Date(tmp[[1]][1]), nrow(d.out))
30 attendance <- do.call("rbind",
31 lapply(list.files(".", pattern="^attendance-.*tsv$"),
32 file.to.attendance.list))
34 attendance.counts <- data.frame(table(attendance$discord.name))
35 colnames(attendance.counts) <- c("discord.name", "num.present")
37 d <- merge(d, attendance.counts,
38 all.x=TRUE, all.y=TRUE,
41 days.list <- lapply(unique(attendance$day), function (day) {
42 day.total <- table(call.list$day == day)[["TRUE"]]
43 lapply(d$discord.name, function (discord.name) {
44 num.present <- nrow(attendance[attendance$day == day & attendance$discord.name == discord.name,])
45 data.frame(discord.name=discord.name,
46 days.present=(num.present/day.total))
50 days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
52 days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
54 attendance.days <- data.frame(discord.name=names(days.tbl),
55 days.present=days.tbl,
56 days.absent=length(list.files(".", pattern="^attendance-.*tsv$"))-days.tbl)
58 d <- merge(d, attendance.days,
59 all.x=TRUE, all.y=TRUE, by="discord.name")
60 d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
62 ## make some visualizations of whose here/not here
63 #######################################################
65 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
68 aes(x=as.factor(num.calls), fill=days.absent, group=days.absent) +
69 geom_bar(color="black") +
70 scale_x_discrete("Number of questions asked") +
71 scale_y_continuous("Number of students") +
72 scale_fill_continuous("Days absent", low="red", high="blue")+
77 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
80 aes(x=as.factor(num.calls), y=days.absent) +
82 scale_x_discrete("Number of questions asked") +
83 scale_y_continuous("Days absent")