# Custom function
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
stat_test <- function(data, formula){
t.test(formula, data) %>%
tidy()
}
# Example 1: pipe-friendly stat_test().
# Two possibilities of usage are available
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Use this
ToothGrowth %>%
group_by(dose) %>%
doo(~stat_test(data =., len ~ supp))
# Or this
ToothGrowth %>%
group_by(dose) %>%
doo(stat_test, len ~ supp)
# Example 2: R base function t.test() (not pipe friendly)
# One possibility of usage
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
comparisons <- ToothGrowth %>%
group_by(dose) %>%
doo(~t.test(len ~ supp, data =.))
comparisons
comparisons$.results.
# Example 3: R base function combined with tidy()
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ToothGrowth %>%
group_by(dose) %>%
doo(~t.test(len ~ supp, data =.) %>% tidy())
Run the code above in your browser using DataLab