rm(list =ls()) # Clear environment-remove all files from your workspacegc() # Clear unused memory
used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
Ncells 606361 32.4 1374645 73.5 NA 715628 38.3
Vcells 1114553 8.6 8388608 64.0 49152 2010577 15.4
cat("\f") # Clear the console
graphics.off() # Clear all graphs
Load Data
Motor Trend Car Road Tests
Description
The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).
A data frame with 32 observations on 11 (numeric) variables.
Does the package need to have the same name as the function?
No !
psych package has describe function.
stargazer package has stargazer function.
# install.packages("stargazer")??stargazer # global searchlibrary(stargazer)
Please cite as:
Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
?stargazer # local searchstargazer(df, type ="text", title ="Summary Statistics Table")
Summary Statistics Table
============================================
Statistic N Mean St. Dev. Min Max
--------------------------------------------
mpg 32 20.091 6.027 10.400 33.900
cyl 32 6.188 1.786 4 8
disp 32 230.722 123.939 71.100 472.000
hp 32 146.688 68.563 52 335
drat 32 3.597 0.535 2.760 4.930
wt 32 3.217 0.978 1.513 5.424
qsec 32 17.849 1.787 14.500 22.900
vs 32 0.438 0.504 0 1
am 32 0.406 0.499 0 1
gear 32 3.688 0.738 3 5
carb 32 2.812 1.615 1 8
--------------------------------------------
I am not printing the output of the following 3 commands.
stargazer(df, type ="text", title ="Summary Statistics Table" )stargazer(df, type ="text", title ="Summary Statistics Table" )stargazer(df, # dataframe/raw datatype ="text", # output title ="Summary Statistics Table"# title )
Tip
More readable code gives arguments for each input into the function, is well alligned, and has comments.
stargazer(... = df, # dataframe/raw datatype ="text", # output title ="Summary Statistics Table"# title )
Summary Statistics Table
============================================
Statistic N Mean St. Dev. Min Max
--------------------------------------------
mpg 32 20.091 6.027 10.400 33.900
cyl 32 6.188 1.786 4 8
disp 32 230.722 123.939 71.100 472.000
hp 32 146.688 68.563 52 335
drat 32 3.597 0.535 2.760 4.930
wt 32 3.217 0.978 1.513 5.424
qsec 32 17.849 1.787 14.500 22.900
vs 32 0.438 0.504 0 1
am 32 0.406 0.499 0 1
gear 32 3.688 0.738 3 5
carb 32 2.812 1.615 1 8
--------------------------------------------
Control Digits and Variable labels
stargazer(... = df, # dataframe/raw datatype ="text", # output title ="Summary Statistics Table", # titledigits =1, # control decimal placescovariate.labels =c("Miles per Gallon", # label variables"# of Cylinders" ) )
Summary Statistics Table
=============================================
Statistic N Mean St. Dev. Min Max
---------------------------------------------
Miles per Gallon 32 20.1 6.0 10.4 33.9
# of Cylinders 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
---------------------------------------------