Search code examples
export-to-excelexport-to-csvcontingency

Exporting deducer's contingency tables as csv or xls


I am working with JGR and using Deducer, and I am creating contingency tables and frequencies using Deducer. I'm mostly interested in exporting these contingency tables and saving them as .csv or xls files.

For my purposes, I don't need the chi-sq or anything like that, just the cross tabs and totals. Of course, the easier the better, but any help would be greatly appreciated.

Here's what the general code and output looks like (coming from 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% |           | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|

Thanks!


Solution

  • 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")