0

我正在使用 JGR 并使用 Deducer,我正在使用 Deducer 创建列联表和频率。我最感兴趣的是导出这些列联表并将它们保存为 .csv 或 xls 文件。

出于我的目的,我不需要 chi-sq 或类似的东西,只需要交叉表和总计。当然,越容易越好,但任何帮助将不胜感激。

这是一般代码和输出的样子(来自Hmisc Table Creation

   Cell Contents
|-------------------------|
|                   Count |
|             Row Percent |
|          Column Percent |
|-------------------------|

Total Observations in Table:  524 

             | asq[, 23] 
    asq[, 4] |        1  |        2  |        3  |        4  |        5  | Row Total | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|
           0 |       76  |       54  |       93  |       46  |       54  |      323  | 
             |   23.529% |   16.718% |   28.793% |   14.241% |   16.718% |   61.641% | 
             |   54.286% |   56.250% |   63.265% |   63.889% |   78.261% |           | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|
           1 |       64  |       42  |       54  |       26  |       15  |      201  | 
             |   31.841% |   20.896% |   26.866% |   12.935% |    7.463% |   38.359% | 
             |   45.714% |   43.750% |   36.735% |   36.111% |   21.739% |           | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|
Column Total |      140  |       96  |      147  |       72  |       69  |      524  | 
             |   26.718% |   18.321% |   28.053% |   13.740% |   13.168% |           | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|

谢谢!

4

1 回答 1

1

There is not a particularly good way to do this in Deducer (though perhaps there should be). If you are using DeducerRichOutput then tables are formatted as html and can be copy/pasted into excel. You can install it with:

install.packages("DeducerRichOutput",,"http://r-forge.r-project.org",type="source")

If you want to do this programatically, you are best off using base R.

xt <- xtabs(~gear+cyl,data=mtcars)
write.csv(addmargins(xt),"tmp.csv")
于 2011-12-20T16:41:28.627 回答