Functions Included

To date, this N741pkg package includes 2 functions tbl.continuous and tbl.cat for creating summary statistics tables for numeric (continuous) data and categorical (or ordinal) variables.

Creating summary statistics tables for numeric (continuous) variables

The tbl.continuous function will work for any numeric variable. Ideally, you will run these statistics on continuous measures but can compute these summary statistics for ordinal data as well. The resulting data.frame output from this function can be used easily with knitr::kable() to create a table of summary statistics. This summary includes both informative descriptives (sample size, missing data, minimum, maximum), parametric statistics (mean, standard deviation), and non-parametric statistics (median, 25th and 75th percentile for the interquartile range).

Example using the mtcars dataset with tbl.continuous

Using the mtcars built-in dataset, you can create separate data.frame object "tables" (t1, t2, ...) and then combine these using rbind() (bind data.frame objects together by rows) to make a bigger data.frame containing the summary stats for multiple variables at once which can be printed using knitr::kable(). Each row of the resulting table is a different variable (column) containing the summary statistics for that variable.

m <- mtcars
t1 <- N741pkg::tbl.continuous(m,m$mpg,"Miles per Gallon")
t2 <- N741pkg::tbl.continuous(m,m$disp,"Engine Displacement")
t3 <- N741pkg::tbl.continuous(m,m$wt,"Car Weight")
t4 <- N741pkg::tbl.continuous(m,m$hp,"Horsepower")
t5 <- N741pkg::tbl.continuous(m,m$qsec,"1/4 mile time")
knitr::kable(rbind(t1,t2,t3,t4,t5),
             caption = "Table of Summary Stats for Numeric Variables in mtcars")

Creating summary statistics tables for categorical (or ordinal) variables

Example using the mtcars dataset with tbl.cat

In the mtcars dataset, there are several ordinal variables for which running frequency summaries is useful. Let's run frequency summaries for:

# create grouped data.frame of m by cylinders
gm <- dplyr::group_by(m,cyl)
t1 <- N741pkg::tbl.cat(gm,gm$cyl)
knitr::kable(t1,
             caption = "Frequency Table for Number of Cylinders")

# create grouped data.frame of m by am
gm <- dplyr::group_by(m,am)
t1 <- N741pkg::tbl.cat(gm,gm$am)
knitr::kable(t1,
             caption = "Frequency Table for Transmission")

# create grouped data.frame of m by gear
gm <- dplyr::group_by(m,gear)
t1 <- N741pkg::tbl.cat(gm,gm$gear)
knitr::kable(t1,
             caption = "Frequency Table for Number of Forward Gears")

Generic Vignette information - included for further examples

Vignettes are long form documentation commonly included in packages. Because they are part of the distribution of the package, they need to be as compact as possible. The html_vignette output type provides a custom style sheet (and tweaks some options) to ensure that the resulting html is as small as possible. The html_vignette format:

Vignette Info

Note the various macros within the vignette section of the metadata block above. These are required in order to instruct R how to build the vignette. Note that you should change the title field and the \VignetteIndexEntry to match the title of your vignette.

Styles

The html_vignette template includes a basic CSS theme. To override this theme you can specify your own CSS in the document metadata as follows:

output: 
  rmarkdown::html_vignette:
    css: mystyles.css

Figures

The figure sizes have been customised so that you can easily put two images side-by-side.

plot(1:10)
plot(10:1)

You can enable figure captions by fig_caption: yes in YAML:

output:
  rmarkdown::html_vignette:
    fig_caption: yes

Then you can use the chunk option fig.cap = "Your figure caption." in knitr.

More Examples

You can write math expressions, e.g. $Y = X\beta + \epsilon$, footnotes^[A footnote here.], and tables, e.g. using knitr::kable().

knitr::kable(head(mtcars, 10))

Also a quote using >:

"He who gives up [code] safety for [code] speed deserves neither." (via)



melindahiggins2000/N741pkg documentation built on May 22, 2019, 6:50 p.m.