qoiqpwqr 发表于 2012-10-15 20:19 
dat
qoiqpwqr大神,
有个问题请教下,table() 表 它是属于什么概念呢,比如向量、矩阵、列表。。。?
看到此楼主的问题, 我其实第一眼想到的是 table() #~~~dxystata版主,lol~~~~
table(), 也是可以用barplot, 而看barplot的help, data 要vector or matrix
#再借用dxystata的例子
a <- data.frame(sex=c(1,1,2,2,1,1), bq=c(1,2,1,2,2,2))
levels(a$bq) <- c("1","2","total")
tm <- subset(a, sex == "1")
tf <- subset(a, sex == "2")
tm$bq <- c("total")
tf$bq <- c("total")
n <- rbind(a, tm , tf)
table(n)
m <- table(n)
barplot(m, beside =T, legend.text = attr(m,"dimnames")$sex)