R
aggregate 2 dplyr
dat <- data.frame(gender=c('M','M','M','M','M','F','F','F','F','F'), num=c(1,2,3,1,2,3,1,2,3,1), h=c(170,180,190,180,170,150,160,170,160,150), w=c(80,70,100,80,60,50,50,60,60,50)) dat$BMI <- dat$w/(dat$h/100)^2 table(dat$gender, dat$num) ## ## 1 2 3 ## F 2 1 2 ##…