0

I am trying to create a summary of my table using summaryBy, that looks like the following

year   qtr   FX_mean     FX_median
2000    1     1000000      1000000
2000    2     2000         1000
2000    3     3000         2000

The FX_mean and FX_median are currency. I am sending it to xtable, and then printing it to a LaTeX file. Now when I format, I was able to get the FX_mean and FX_median with 2 decimal points. But since it is currency, I want a "," after every thousand i.e. 1,000,000. I tried to use something like

 format.args = list(big.mark = ",", decimal.mark = "."))

print(result, type="latex", file="output.tex", include.rownames=FALSE, booktabs = TRUE, floating = FALSE, format.args = list(big.mark = ",", decimal.mark = "."))

But it applies to the entire dataframe and so even for the years -- so I see 2,000 ... 2,007, etc. Is there a way to have the big.mark apply to FX_mean and FX_median alone?

year   qtr     FX_mean          FX_median
2000    1     1,000,000.00      1,000,000.00
2000    2     2,000.00         1,000.00
2000    3     3,000.00         2,000.00
rajvijay
  • 1,641
  • 4
  • 23
  • 28

1 Answers1

0

It seems that this is not possible directly, because format.args applies to each column, you cannot specify it as a list, with one element for each column. Here is the relevant code from print.xtable: https://github.com/cran/xtable/blob/master/R/print.xtable.R#L567

So a workaround is to convert that column to character, before handing the table to xtable:

mytab$FX_mean <- format(mytab$FX_mean, big.mark = ",", decimal.mark = ".")

and similarly for the other column.

Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53