How to format a table (data.frame) with publication quality in pdf (latex) in R?

8

Suppose the following table:

tabela <- structure(list(Sexo = structure(c(1L, 1L, 2L, 2L), .Label = c("Homem", 
"Mulher"), class = "factor"), Grupo = structure(c(1L, 2L, 1L, 
2L), .Label = c("A", "B"), class = "factor"), Média = c(0.2655086631421, 
0.37212389963679, -0.835628612410047, 1.59528080213779), Var = c(0.329507771815361, 
0.820468384118015, 0.572853363351896, 0.908207789994776)), .Names = c("Sexo", 
"Grupo", "Média", "Var"), row.names = c(NA, -4L), class = "data.frame")

tabela
    Sexo Grupo      Média        Var
1  Homem     A  0.2655087  0.3295078
2  Homem     B  0.3721239  0.8204684
3 Mulher     A -0.8356286  0.5728534
4 Mulher     B  1.5952808  0.9082078

How to leave it in a publication format, for a file in pdf (using latex for example)?

    
asked by anonymous 08.03.2014 / 02:13

3 answers

8

You can also use the package stargazer

library(stargazer)
stargazer(tabela, summary=FALSE)

Result:

    
11.03.2014 / 21:31
7

One package that I find fantastic is tables . He is very flexible. For example, sorting tabela in three different ways:

library(tables)
tabela1 <- tabular(~(Sexo)*Heading()*Grupo*Heading()*identity*(Média+Var), data=tabela)
tabela2 <- tabular((Sexo)~(Grupo)*Heading()*identity*(Média+Var), data=tabela)
tabela3 <- tabular(Sexo*Grupo~Heading()*identity*(Média+Var), data=tabela)

To generate the code latex :

latex(tabela1)
latex(tabela2)
latex(tabela3)

Results:

    
08.03.2014 / 14:28
4

You can use the xtable package. First, you need to download the package. In R, enter the following command:

install.packages("xtable")

Once installed, load it:

library("xtable")

Put your tabela in the format data.frame and apply the command:

xtable(tabela)
    
08.03.2014 / 02:43