packs <- c("devtools", "knitr", "MASS", "htmlTable") lapply(packs, function(x) require(x, character.only = T)) install_github("lisaerein/nicetable") library(nicetable) help(nicetable) options(knitr.kable.NA = '.')
head(survey <- survey)
+ df: name of data frame. + covs: character vector of column names to include in table. + type: numeric vector of variable types (1 for continuous and 2 for categorical).
tab <- nicetable(df = survey, covs = names(survey), type = c(2,1,1,2,2,1,2,2,2,1,2,1))
labs <- c("Gender", "Span of writing hand", "Span of non-writing hand", "Writing hand", "Which arm is on top when you fold your arms?", "Pulse (bpm)", "Which arm is on top when you clap?", "Exercise frequency", "Smoking frequency", "Height (cm)", "Which units did students use", "Age (years)") tab <- nicetable(df = survey, covs = names(survey), labels = labs, type = c(2,1,1,2,2,1,2,2,2,1,2,1), stats = c("mean_sd", "median", "iqr", "range"), cont.dec = 1)
tab <- nicetable(df = survey, by = "Sex", covs = names(survey)[-1], type = c(1,1,2,2,1,2,2,2,1,2,1))
tab <- nicetable(df = survey, by = "Sex", covs = names(survey)[-1], type = c(1,1,2,2,1,2,2,2,1,2,1), percent = 1, perc.dec = 2, dispN = TRUE)
tab <- nicetable(df = survey, by = "Sex", covs = names(survey)[-1], type = c(1,1,2,2,1,2,2,2,1,2,1), tests = "np")
tab <- nicetable(df = survey, allcol = FALSE, by = "Sex", covs = names(survey)[-1], type = c(1,1,2,2,1,2,2,2,1,2,1), tests = "p", caption = "Table 1: Survey responses by gender", htmltitle = "Survey questions", color = "powderblue")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.