预处理
caff.marital<-matrix(c(625,1537,598,242,36,46,38,21,218,327,106,67),nrow = 3,byrow = T)#生成表格,需要一个作为单独向量的表格值的变量
colnames(caff.marital)<-c("0","1-150","151-300",">300")#表格列名称命名
rownames(caff.marital)<-c("Married","Prev.married","Single")#行名称命名
caff.marital
names(dimnames(caff.marital))<-c("marital","consution")#添加变量名
caff.marital
as.data.frame(as.table(caff.marital))#把表格转换为计数的数据框
4.6表格的图形显示
4.6.1条形图
total.caff<-margin.table(caff.marital,2)#计算列总和,生成为total.caff的新表
total.caff
consution
0 1-150 151-300 >300
879 1910 742 330