Let me create some data before I ask my question.
my.data <- data.frame(A = sample(seq(1,100,by=5),10,replace=TRUE),W = rnorm(10),X =sample(1:10),Y = sample(
Building off of user2030503's answer,
# install.packages('simsalapar')
library(simsalapar)
utils::toLatex(result1)
The function toLatex is an S3 generic so passes to simsalapar:::toLatex.ftable()
when given an ftable object. Alternatively you can just do simsalapar:::toLatex.ftable(result1)
.
Once that was done I needed to include \usepackage{booktabs}
in the latex preamble as toLatex.ftable
uses \toprule
. Alternatively you can pass booktabs=FALSE
.
It also looks like toLatex.ftable
trims out trailing zeroes. To fix that this is what I did (see the answer to Formatting Decimal places in R for format()
):
result1[1:nrow(result1),1:ncol(result1)] %<>% as.numeric %>% format(nsmall=2,digits=3)
this converts the matrix of the ftable to a character matrix, but toLatex.ftable
still works.
I also found it helpful to \usepackage{pdflscape}
and wrap my table with \begin{landscape}
and \end{landscape}
because these contingency tables can be quite wide.
Use the toLatex()
function provided by the simsalapar Package.
library(simsalapar)
toLatex(result1)
Method 1:
require(MIfuns)
require(Hmisc)
latex(ftable2data.frame(result1))
As an alternative, memisc provides toLatex methods for ftable objects.
library(memisc)
toLatex(result1)
You can use the package xtable:
library(xtable)
mytable=ftable(mydata)
print(
xtable(format(mytable)),file="~/Desktop/mytable.tex"
)
I don't know how it compares to the other options given.