library(vcd)
head(Arthritis)

table(Arthritis$Treatment,Arthritis$Improved)
with(Arthritis,table(Treatment,Improved))
mytable <- xtabs(~Treatment+Improved,data = Arthritis)
with(Arthritis,xtabs(~Treatment+Improved,data = Arthritis))

margin.table(mytable,2) # sum by row
prop.table(mytable,2)  #proportion by column
prop.table(mytable)  #proportion by total

addmargins(mytable)
addmargins(mytable,1)
addmargins(prop.table(mytable,2),1)


library(gmodels)
CrossTable(Arthritis$Treatment,Arthritis$Improved) ##SAS format

  

posted on 2019-08-16 16:47  be·freedom  阅读(3111)  评论(0编辑  收藏  举报