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.
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).
tbl.continuous(x,x$a,"label for var a")
df
df$var
"var label"
data.frame
object with 1 row and 10 variables/columns. These 10 columns include:item
: the variable label providedn
: the number of non-missing valuesmissing
: the number of missing valuesmin
: the minimum valueavg
: the average/mean valueSD
: the standard deviation of the valuesmedian
: the median valueQ1
: the 25th percentile (1st quartile) of the valuesQ3
: the 75th percentile (3rd quartile) of the valuesmax
: the maximum valuemtcars
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")
tbl.cat(gx,gx$b)
gdf
SEE NOTEgdf$var
dplyr::group_by()
function. See the example provided with help(tbl.cat)
. You need to "group_by" the categorical (or ordinal) variable you want to make the table for.data.frame
object with 1 row and 3 variables/columns. These 3 columns include:var
: the categorical variable categories or ordinal levelsfreq
: the frequencies (or counts) for each category or levelpct
: the percentage of the total number of rows - these percents are NOT adjusted for missing. However, the frequency and percentage of NA
s are provided.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:
cyl
"Number of Cylinders"am
"Transmission (0=automatic, 1=manual)"gear
"Number of forward gears"# 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")
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:
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.
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
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.