Format Output into a Table

Learn how to format output into a table using R.

Loading add-on packages in R

An important part of presenting research findings is to format output into a table. The base R package, however, does not produce nicely formatted output. As noted earlier, one of the most important strengths of R is the availability of add-on packages R users provide for free through the CRAN family of internet sites. R is reported to have nearly 12,000 free add-on packages as of 2017. One free package, stargazer, allows us to present the statistical results in a formatted table.

To apply the package to our data frame vd, we will learn how to complete the following tasks: install a user-written package, load the package into R, and apply the stargazer() function to produce a table.

Note that an add-on package only needs to be installed once for future use. Hence, we do not have to include and run the installation command in our R program. However, in every R session, if we plan to use an add-on package, we have to load it into R via the library() function. After loading, a citation of each package also shows up for users. The R code is as follows:

Get hands-on with 1200+ tech skills courses.