The model: there are two course “A” and “B”; each attended by students of a certain education level. I would like to make a summary table of the factors.
I thought aggregation can do the job, but I am puzzled with counting the factor type of gender. I would like to make a summary of which the output should look like this.
course edu-level gender sum_value
A prim male <cnt>
A prim female <cnt>
A sec male <cnt>
A sec female <cnt>
...
# two courses "A" and "B"
module<-as.factor(c(rep("A",5), rep( "B",6)))
# gender per course
gender<-as.factor(c(rep("female",2), rep("male",3), rep("female",3), rep("male",3)))
# education level per gender: primary, secondary or tertiary
edu<-as.factor(c("prim", "sec", "tert", "prim", "sec", "tert","prim", "sec", "tert","prim", "sec"))
course<-data.frame(module, gender, edu)
aggregate(course$gender, list(course$module, course$edu), sum)
# Error in Summary.factor(1:2, na.rm = FALSE) :
# ‘sum’ not meaningful for factors