如何从“表格”功能获得行百分比?

时间:2016-02-23 00:42:33

标签: r tabular

 df<- data.frame(ministry=paste("ministry", sample(1:3,20,replace=T)),
                  department=paste("department", sample(1:3,20,replace=T)),
                  program=paste("program",sample(letters[1:5],20,replace=T)),
                  budget=runif(20)*1e6)
library(tables)
tabular(1+ministry+program~1+department+(Avg=(mean*budget)),data=df)

#                               department                                Avg   
#                           All department  1 department  2 department  3 budget
#               All         20  6             7             7             632110
#      ministry ministry  1  6  3             2             1             485676
#               ministry  2  6  2             0             4             669535
#               ministry  3  8  1             5             2             713866
#      program  program  a   1  0             0             1             952492
#               program  b   5  2             3             0             579794
#               program  c   4  2             2             0             646403
#               program  d   4  0             1             3             558388
#               program  e   6  2             1             3             661929

您好, 如果是R.我正在研究交叉制表 如何获得“部门”的行百分比而非计数?

0 个答案:

没有答案