knitr::opts_chunk$set(comment = NA) Sys.setenv(TZ = "US/Central")
# Load packages library(tidyverse) library(bfuncs)
data("mtcars")
Helpful websites:
SO summarise with multiple return values
I originally created the tabstat function awhile back. I didn't create it to work with dplyr pipes and it never worked with grouped variables. Need to address both of those issues below.
I can calculate the mean, and many other statistics for continuous variables using dplyr::summarise. However, dplyr::summarise can only be used to return single number statistics. Because 95% CI's do not fit this requirement, I have to build my own function.
Acutally, maybe I should just use the do function and make a note in r notes. still need to find a function that returns 95% CI's to use with "do".
mtcars %>% summarise(mean_mpg = mean(mpg))
mtcars %>% group_by(cyl) %>% summarise(mean_mpg = mean(mpg))
mtcars %>% do(tabstat(.$mpg, stats = c("n", "ci")))
mtcars %>% group_by(cyl) %>% do(tabstat(.$mpg, stats = c("n", "ci")))
So, using "do" isn't necessarily the most elegant solution ever, but it seems to work just fine.
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.