I\'m using the R package stargazer to create high-quality regression tables, and I would like to use it to create a summary statistics table. I have a factor variable in my
The package tables
can be useful for this task.
library(car)
library(tables)
data(Blackmore)
# percent only:
(x <- tabular((Factor(group, "") ) ~ (Pct=Percent()) * Format(digits=4),
data=Blackmore))
##
## Pct
## control 37.99
## patient 62.01
# percent and counts:
(x <- tabular((Factor(group, "") ) ~ ((n=1) + (Pct=Percent())) * Format(digits=4),
data=Blackmore))
##
## n Pct
## control 359.00 37.99
## patient 586.00 62.01
Then it's straightforward to output this to LaTeX:
> latex(x)
\begin{tabular}{lcc}
\hline
& n & \multicolumn{1}{c}{Pct} \\
\hline
control & $359.00$ & $\phantom{0}37.99$ \\
patient & $586.00$ & $\phantom{0}62.01$ \\
\hline
\end{tabular}