#Make a summary table
set.seed(123)
data <-
heart_disease %>%
dplyr::group_by(
Sex,
BloodSugar,
HeartDisease
) %>%
dplyr::summarise(
Mean = mean(Age),
SD = sd(Age),
.groups = "drop"
) %>%
dplyr::mutate(
Random =
rbinom(nrow(.), size = 1, prob = .5) %>%
factor
)
data %>%
stretch(
key = c(BloodSugar, HeartDisease),
value = c(Mean, SD, Random)
)
data %>%
stretch(
key = where(is.factor),
value = where(is.numeric)
)
data %>%
stretch(
key = c(where(is.factor), where(is.logical)),
value = where(is.numeric)
)
Run the code above in your browser using DataLab