knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
The goal of tidytableR is to is to reshape data from a tidy format into
one that is suitable for presentation. Specifically, it works best when used
to make complex, publication-quality tables from output created by
dplyr::summarise
or tidyr::gather
. It allows users to
map column names from an input data frame to elements of an output table.
The package was developed from code meant to act as a wrapper script for the
htmlTable
function in the
htmlTable
package. In fact, its first release was as the tidyHtmlTable
function within
the htmlTable
package. Therefore, many of the variable names and symantics
used within are related to those used in the htmlTable
package.
You can install tidytableR from github with:
# install.packages("devtools") devtools::install_github("graggsd/tidytableR")
library(tidytableR) library(magrittr) library(dplyr) library(tidyr) library(tibble)
Turn mtcars
data into a tidy dataset.
td <- mtcars %>% rownames_to_column %>% select(rowname, cyl, gear, hp, mpg, qsec) %>% gather(per_metric, value, hp, mpg, qsec)
Compute 4 summary statistics for each of the 3 performance metrics, grouped number of cylinders and gears.
tidy_summary <- td %>% group_by(cyl, gear, per_metric) %>% summarise(Mean = round(mean(value), 1), SD = round(sd(value), 1), Min = round(min(value), 1), Max = round(max(value), 1)) %>% gather(summary_stat, value, Mean, SD, Min, Max) %>% ungroup %>% mutate(gear = paste(gear, "Gears"), cyl = paste(cyl, "Cylinders"))
tidy_summary %>% tidy_htmlTable(header = "gear", cgroup1 = "cyl", cell_value = "value", rnames = "summary_stat", rgroup = "per_metric")
tidy_summary %>% tidy_htmlTable(header = "summary_stat", cgroup1 = "per_metric", cell_value = "value", rnames = "gear", rgroup = "cyl")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.