I want to generate an R table for Latex

Asked

Viewed 1,628 times

2

I want to generate a table with the R Summary data with the results I got, I know there’s a library called Stargazer that does, but I couldn’t find the documentation.

2 answers

2

> require("xtable")
Carregando pacotes exigidos: xtable
> data("iris")
> xtable(summary(iris))
% latex table generated in R 3.4.1 by xtable 1.8-2 package
% Wed Sep 20 15:24:36 2017
\begin{table}[ht]
\centering
\begin{tabular}{rlllll}
\hline
&  Sepal.Length &  Sepal.Width &  Petal.Length &  Petal.Width &       Species \\ 
 \hline
1 & Min.   :4.300   & Min.   :2.000   & Min.   :1.000   & Min.   :0.100   & setosa    :50   \\ 
2 & 1st Qu.:5.100   & 1st Qu.:2.800   & 1st Qu.:1.600   & 1st Qu.:0.300   & versicolor:50   \\ 
3 & Median :5.800   & Median :3.000   & Median :4.350   & Median :1.300   & virginica :50   \\ 
4 & Mean   :5.843   & Mean   :3.057   & Mean   :3.758   & Mean   :1.199   &  \\ 
5 & 3rd Qu.:6.400   & 3rd Qu.:3.300   & 3rd Qu.:5.100   & 3rd Qu.:1.800   &  \\ 
6 & Max.   :7.900   & Max.   :4.400   & Max.   :6.900   & Max.   :2.500   &  \\ 
\hline
\end{tabular}
\end{table}

If I understand well what you want, one possibility is to use the "xtable" package returns an R object in the latex table format.

1

A solution using the package stargazer is:

install.packages("stargazer")
library(stargazer)

data("iris")
stargazer(do.call(cbind, lapply(iris,summary)), type = "latex")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.