성별 차이, 학번별 차이를 파악하기 위하여 tapply() 활용

kable(t(as.matrix(table("몇 개나 나눠줄래요?" = chocolate), 1)))
0 1 2 3 4 5 6 10
2 2 5 12 14 21 1 3
kable(table("성별" = sex, "몇 개나 나눠줄래요?" = chocolate))
0 1 2 3 4 5 6 10
1 1 3 5 8 9 1 2
1 0 1 6 6 9 0 1
pander(tapply(chocolate, sex, summary))
pander(tapply(chocolate, year.2, summary))
pander(tapply(chocolate, list(year, sex), function(x) format(mean(x, na.rm = TRUE), digits = 2, nsmall = 1)))
 
13학번 이후 3.2 4.2
12학번 이전 4.6 4.0
pander(tapply(chocolate, list(year.2, sex), function(x) format(mean(x, na.rm = TRUE), digits = 2, nsmall = 1)))
 
12학번 이후 4.1 4.1
11학번 이전 4.2 4.0

kable 을 사용하려면 aggregate 활용

chocolate.sex.ag <- aggregate(chocolate ~ sex, data = ew.gorilla.full, summary)
names(chocolate.sex.ag)
## [1] "sex"       "chocolate"
chocolate.sex.xtabs <- xtabs(chocolate ~ sex, chocolate.sex.ag)
kable(chocolate.sex.xtabs)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0 3 4 4.2 5 10
0 3 4 4.1 5 10
chocolate.year.ag <- aggregate(chocolate ~ year, data = ew.gorilla.full, summary)
names(chocolate.year.ag)
## [1] "year"      "chocolate"
chocolate.year.xtabs <- xtabs(chocolate ~ year, chocolate.year.ag)
kable(chocolate.year.xtabs)
Min. 1st Qu. Median Mean 3rd Qu. Max.
13학번 이후 0 3 4 3.8 5 10
12학번 이전 2 3 4 4.4 5 10
chocolate.year.2.ag <- aggregate(chocolate ~ year.2, data = ew.gorilla.full, summary)
names(chocolate.year.2.ag)
## [1] "year.2"    "chocolate"
chocolate.year.2.xtabs <- xtabs(chocolate ~ year.2, chocolate.year.2.ag)
kable(chocolate.year.2.xtabs)
Min. 1st Qu. Median Mean 3rd Qu. Max.
12학번 이후 0 3 4 4.1 5 10
11학번 이전 2 3 4 4.2 5 10