Descriptive statistics: in text format
mydata <- mtcars
install.packages("stargazer") #
Use this to install it, do this only once
library(stargazer)
stargazer(mydata, type = "text", title="Descriptive statistics", digits=1, out="table1.txt")
OTR
Descriptive statistics
==============================================================
Statistic mpg cyl disp hp drat wt qsec vs am gear carb
N 32 32 32 32 32 32 32 32 32 32 32
Mean 20.1 6.2 230.7 146.7 3.6 3.2 17.8 0.4 0.4 3.7 2.8
St. Dev. 6.0 1.8 123.9 68.6 0.5 1.0 1.8 0.5 0.5 0.7 1.6
Min 10.4 4 71.1 52 2.8 1.5 14.5 0 0 3 1
Max 33.9 8 472.0 335 4.9 5.4 22.9 1 1 5 8
--------------------------------------------------------------
Descriptive statistics
======================================
Statistic N Mean St. Dev. Min Max
mpg 32 20.1 6.0 10.4 33.9
cyl 32 6.2 1.8 4 8
disp 32 230.7 123.9 71.1 472.0
hp 32 146.7 68.6 52 335
drat 32 3.6 0.5 2.8 4.9
wt 32 3.2 1.0 1.5 5.4
qsec 32 17.8 1.8 14.5 22.9
vs 32 0.4 0.5 0 1
am 32 0.4 0.5 0 1
gear 32 3.7 0.7 3 5
carb 32 2.8 1.6 1 8
--------------------------------------
directory with whatever name you
write in the out option. You can open
# Same output, transposed (variables in columns)
stargazer(mydata, type = "text", title="Descriptive statistics", digits=1, out="table1.txt", flip=TRUE)
Use this option if you want
the variables in columns
For more details/options type ?stargazer
stargazer will automatically
recognize the type of object, and will
produce the appropriate output. In
the case of data frames, it will display
summary statistics .
4