rdigitsxtable

R Sweave: digits number in xtable of prop.table


I'm making an xtableFtable on R Sweave and can't find a way to suppress the digits with this code. What I am doing false? I've read that it can happen if your values aren't numeric but factor or character, but is prop.table making them non-numeric? I'm lost...

library(xtable)
a <- ftable(prop.table(table(mtcars$mpg, mtcars$hp), margin=2)*100)
b <- xtableFtable(a, method = "compact", digits = 0)
print.xtableFtable(b, rotate.colnames = TRUE)

I've already tried with digits=c(0,0,0,0...) too.


Solution

  • You could use options(digits) to control how many digits will print. Try something like options(digits = 4) as the first line of your code (change 4 to whatever value you want between 1 and 22). See ?options for more information.

    Or round the values before printing

    a = round(ftable(prop.table(table(mtcars$mpg, mtcars$hp), margin=2)*100), 2)
    b = xtableFtable(a, method = "compact")
    print.xtableFtable(b, rotate.colnames = TRUE)