# NOT RUN {
require(tidyverse)
#1) Return a list
heart_disease %>%
stratiply(
strata = c("Sex", "HeartDisease"),
f = head
)
#2) Unseparated strata column
heart_disease %>%
stratiply(
strata = c("Sex", "HeartDisease"),
f = head,
bind = TRUE
)
#3) Separated strata column
heart_disease %>%
stratiply(
strata = c("Sex", "HeartDisease"),
f = head,
bind = TRUE,
separate = TRUE
)
#4) Custom function
heart_disease %>%
stratiply(
strata = c("Sex", "HeartDisease"),
f = function(x)
x %>%
select_if(is.numeric) %>%
map(mean, na.rm = TRUE),
bind = TRUE,
separate = TRUE
)
#5) Regular expression
heart_disease %>%
stratiply(
strata = matches("^(S|H)"),
f = function(x)
x %>%
select_if(is.numeric) %>%
map(mean, na.rm = TRUE),
bind = TRUE,
separate = TRUE
)
# }
Run the code above in your browser using DataLab