knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Create Stata-like tables in the R console
You can install statascii from GitHub with:
# install.packages("devtools") devtools::install_github("gvelasq/statascii")
# setup library(dplyr) library(stringr) library(statascii) # a. demonstrate 'oneway' flavor for one-way tables of frequencies a <- mtcars %>% count(gear) %>% rename(Freq. = n) a <- a %>% add_row(gear = "Total", Freq. = sum(a[, 2])) statascii(a, flavor = "oneway") # b. demonstrate 'oneway' flavor with no padding b <- mtcars %>% count(gear) %>% rename(Freq. = n) b <- b %>% add_row(gear = "Total", Freq. = sum(b[, 2])) statascii(b, flavor = "oneway", padding = "none") # c. demonstrate 'twoway' flavor for n-way tables of frequencies c <- mtcars %>% count(gear, carb, am) %>% rename(Freq. = n) c <- c %>% ungroup() %>% add_row(gear = "Total", carb = "", am = "", Freq. = sum(c[, 4])) statascii(c, flavor = "twoway") # d. demonstrate 'twoway' flavor with dashed group separators d <- mtcars %>% count(gear, carb, am) %>% rename(Freq. = n) d <- d %>% ungroup() %>% add_row(gear = "Total", carb = "", am = "", Freq. = sum(d[, 4])) statascii(d, flavor = "twoway", separators = TRUE) # e. demonstrate 'summary' flavor for summary statistics e <- mtcars %>% group_by(gear) %>% summarize( Obs = n(), Mean = mean(gear), "Std. Dev." = sd(gear), Min = min(gear), Max = max(gear) ) statascii(e, flavor = "summary") # f. demonstrate wrapping feature for wide tables f <- mtcars %>% mutate(cyl2 = cyl, vs2 = vs, am2 = am, carb2 = carb) %>% filter(gear != 5) %>% count(gear, carb, am, vs, cyl, carb2, am2, vs2, cyl2) %>% rename(Freq. = n) %>% ungroup() f <- f %>% add_row(gear = "Total", Freq. = sum(f[, 10])) f[is.na(f)] <- "" statascii(f, flavor = "oneway", separators = TRUE)
statascii()
borrows heavily from asciify()
.
asciify()
was written by @gavinsimpson in StackOverflow and GitHub Gist.
statascii()
was written by @gvelasq in Github Gist and now has its own GitHub package.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.