I am trying to figure out how to manipulate the data here. The image shows only one course but I have multiple courses and course numbers that range from 2010 to 2017. How should I go about adding a column that shows the median grade for a certain course based on the year, taught and term? We have the number of kids who got a certain grade but not the actual grades. I am expecting that the median grade column would should 11 duplicates for the 11 different grades based on each "taught" variable. Taught can only have two values, either "here" or "there".
I have tried using the aggregate function but this problem doesn't seem like something that can be solved with high-level functions. The db is DBKids in R. I just can't seem to think of a way that can help me with this issue. Thanks!
Edit: Reproducible code
structure(list(sessionYear = c(2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010), courseNumber = c("20", "20",
"20", "20", "20", "20", "20", "20", "20", "20", "20", "20", "20",
"20", "20", "20", "20", "20", "20", "20", "20", "20"),
courseName = c("KidsLearn", "KidsLearn", "KidsLearn", "KidsLearn",
"KidsLearn", "KidsLearn", "KidsLearn", "KidsLearn", "KidsLearn",
"KidsLearn", "KidsLearn", "KidsLearn", "KidsLearn", "KidsLearn",
"KidsLearn", "KidsLearn", "KidsLearn", "KidsLearn", "KidsLearn",
"KidsLearn", "KidsLearn", "KidsLearn"), Taught = c("There",
"Here", "There", "Here", "There", "Here", "There",
"Here", "There", "Here", "There", "Here", "There",
"Here", "There", "Here", "There", "Here", "There",
"Here", "There", "Here"), Term = c("1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1"), averageGrade = c(83, 84, 83, 84, 83, 84,
83, 84, 83, 84, 83, 84, 83, 84, 83, 84, 83, 84, 83, 84, 83, 84
), Grade = c("F", "F", "D", "D", "C3", "C3", "C2", "C2", "C1",
"C1", "B3", "B3", "B2", "B2", "B1", "B1", "A3", "A3", "A2", "A2",
"A1", "A1"), numberOfKids = c(1, 0, 0, 0, 1, 0, 1, 0, 0, 0,
3, 0, 3, 2, 6, 0, 14, 7, 24, 4, 18, 4)), class = "data.frame", row.names = c(NA,
-22L), .Names = c("sessionYear", "courseNumber", "courseName",
"Taught", "Term", "averageGrade", "Grade", "numberOfKids"))
Hope this helps.