1、table()
a_1 <- as.data.frame(table(a$RACE,a$Obesity))
2、xtabs()
race <- as.data.frame(xtabs(~RACE+Obesity,data = a,addNA=F))
3、CrossTable()
library(gmodels) #加载包
a_3 <- as.data.frame(CrossTable(a$RACE,a$Obesity,digits = 0,prop.r = T,prop.c = F,
prop.t = F,prop.chisq = F,chisq = T,format = "SPSS"))
网友评论