Function to aggregate data for youth vs. adult comparison
Source:R/eda_functions.R
aggregate_data.RdFunction to aggregate data for youth vs. adult comparison
Examples
sample_data <- data.frame(
age = c("18-24", "25-34", "35-44"),
alcohol.use = c(80, 75, 60),
alcohol.frequency = c(20, 15, 10),
marijuana.use = c(50, 30, 20),
heroin.frequency = c(5, 3, 2),
class = c("youth", "adult", "adult"),
n = c(100, 200, 150)
)
aggregate_data(sample_data)
#> # A tibble: 10 × 4
#> class total_n variable value
#> <chr> <dbl> <chr> <dbl>
#> 1 adult 350 alcohol.use 68.6
#> 2 adult 350 alcohol.frequency 12.9
#> 3 adult 350 marijuana.use 25.7
#> 4 adult 350 heroin.frequency 2.57
#> 5 adult 350 n 179.
#> 6 youth 100 alcohol.use 80
#> 7 youth 100 alcohol.frequency 20
#> 8 youth 100 marijuana.use 50
#> 9 youth 100 heroin.frequency 5
#> 10 youth 100 n 100