I would like to use stargazer to produce summary statistics for each category of a grouping variable. I could do it in separate tables, but I'd like it all in one – if that is not unreasonably challenging for this package.
For example
library(stargazer)
stargazer(ToothGrowth, type = "text")
#>
#> =========================================
#> Statistic N Mean St. Dev. Min Max
#> -----------------------------------------
#> len 60 18.813 7.649 4.200 33.900
#> dose 60 1.167 0.629 0.500 2.000
#> -----------------------------------------
provides summery statistics for the continues variables in ToothGrowth
. I would like to split that summery by the categorical variable supp
, also in ToothGrowth
.
Two suggestions for desired outcome,
stargazer(ToothGrowth ~ supp, type = "text")
#>
#> ==================================================
#> Statistic N Mean St. Dev. Min Max
#> --------------------------------------------------
#> OJ len 30 16.963 8.266 4.200 33.900
#> dose 30 1.167 0.634 0.500 2.000
#> VC len 30 20.663 6.606 8.200 30.900
#> dose 30 1.167 0.634 0.500 2.000
#> --------------------------------------------------
#>
stargazer(ToothGrowth ~ supp, type = "text")
#>
#> ==================================================
#> Statistic N Mean St. Dev. Min Max
#> --------------------------------------------------
#> len
#> _by VC 30 16.963 8.266 4.200 33.900
#> _by VC 30 1.167 0.634 0.500 2.000
#> _tot 60 18.813 7.649 4.200 33.900
#>
#> dose
#> _by OJ 30 20.663 6.606 8.200 30.900
#> _by OJ 30 1.167 0.634 0.500 2.000
#> _tot 60 1.167 0.629 0.500 2.000
#> --------------------------------------------------
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…