I\'ve got data created from the HairEyeColor data
HairEyeColor
HEC = as.data.frame(HairEyeColor)
which is
We do a group by summarise and then spread
spread
library(tidyerse) HEC %>% group_by(Hair, Eye) %>% summarise(Freq = sum(Freq)) %>% spread(Eye, Freq)
It can be also done in a one-liner
xtabs(Freq ~ Eye + Hair, HEC)