Skip to content

How to print the frequency table (produced by the command "table" to Excel

3 messages · Jim Lemon, John

#
Hi,

   How could we print the frequency table (produced by "table") to an Excel
file?
   Is there an easy way to do so? Thanks,

Miao
z
y   a b c
  1 0 0 1
  2 0 1 0
  3 1 0 0
y z Freq
1 1 a    0
2 2 a    0
3 3 a    1
4 1 b    0
5 2 b    1
6 3 b    0
7 1 c    1
8 2 c    0
9 3 c    0
z
y   a b c
  1 0 0 1
  2 0 1 0
  3 1 0 0
z
y   a b c
  1 0 0 1
  2 0 1 0
  3 1 0 0
[1] "integer"
#
Hi jpm miao,
You can get CSV files that can be imported into Excel like this:

library(prettyR)
sink("excel_table1.csv")
delim.table(table(df[,c("y","z")]))
sink()
sink("excel_table2.csv")
delim.table(as.data.frame(table(df[,c("y","z")])),label="")
sink()
sink("excel_table3.csv")
delim.table(as.matrix(table(df[,c("y","z")])),label="")
sink()

Jim
On Wed, Apr 27, 2016 at 8:35 AM, jpm miao <miaojpm at gmail.com> wrote:
3 days later
#
Jim,

   Thanks for creating such a fantastic package "prettyR".
   I want to print the pretty frequency table (with row total and column
total) to an excel (or csv ) file. Is it possible?
A B Total
A 8 10 18
B 7 5 12
C 9 11 20
Total 24 26 50

   Two issues I encountered (See the attached csv file).
1. When I tried to print the above table to csv file, all elements on the
same row are printed in one cell.
2. If I write "delim.table(alpha tab)", the table is distorted (see
attached). Of course, I can adjust it manually but sometimes the number of
files is big.

    Thanks!

Miao
Crosstabulation of alpha1 by alpha2
alpha2
alpha1      A      B
A      8     10     18
   44.44  55.56      -
   33.33  38.46  36.00

B      7      5     12
   58.33  41.67      -
   29.17  19.23  24.00

C      9     11     20
      45     55      -
   37.50  42.31  40.00

      24     26     50
      48     52    100
alphatab

A B Total
A 8 10 18
B 7 5 12
C 9 11 20
Total 24 26 50
2016-04-26 16:14 GMT-07:00 Jim Lemon <drjimlemon at gmail.com>: