0

Here is my code to create the table(s)

tt <- xtabs( ~ Support + Service.Affiliation + Report.Type + Referral, 
             data = flatcut1)
ty <- addmargins(tt)

This makes nine tables that I can see in the console and looks great. My problem is I need to export them to excel with the formatting that is in the console. Tables If possible I'd love to change the title but I can live with it.

Here are the first or nine tables it generates.

, , Report.Type = R, Referral = C

                                           Service.Affiliation
Support                                        A1    A2   A3    A4   Sum
  Bx                                           85    28    34    65   212
  Cx                                           8     3     2     6    19
  Dx                                           0     0     0     0     0
  Lx                                           8     1     1     5    15
  Mx                                           20     5     1    16    42
  Other                                        50     8    21    68   147
  Rx                                          158    12    13    94   277
  Vx                                           10    11    35    66   122
  Sum                                         339    68   107   320   834

, , Report.Type = U, Referral = C

                                           Service.Affiliation
Support                                        A1    A2   A3    A4   Sum
 DELETED

I am more familiar with SAS and for that I would use proc tabulate and this would be exactly what I want.

When trying to copy and paste to excel it makes every row a single cell, I can to text to column but this isn't a good long term solution with the frequency I need to create this report.

When I try dt <- as.data.frame(ty), it makes a flat file but I need it to still look like a table/report. Also, write.csv also make a very odd flat file.

And here is some as.data.matrix that just produced errors.

pw=as.data.frame.matrix(ty)
Error in `[.default`(x, , i) : incorrect number of dimensions

> pw=as.data.frame.matrix(ty\[1:9\])
> Error in seq_len(ncols) :
> argument must be coercible to non-negative integer
> In addition: Warning message:
> In seq_len(ncols) : first element used of 'length.out' argument
> pw=as.data.frame.matrix(ty\[1\])
> Error in seq_len(ncols) :
> argument must be coercible to non-negative integer
> In addition: Warning message:
> In seq_len(ncols) : first element used of 'length.out' argument
kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28

0 Answers0