The numeric counterpart to calc_percentage(): a one-liner for the
summarise(mean, median, sd) blocks used on age and other continuous
variables, with optional grouping.
Arguments
- data
A data frame.
- column
Numeric column to summarise (unquoted).
- by
Optional grouping column(s); see
calc_percentage().- na_rm
Drop
NAbefore summarising. Defaults toTRUE.- weights
Survey weighting:
NULL(default) uses the session scheme fromset_weights()if set;FALSEforces unweighted; or pass an ad-hoc scheme. When weighting is active themean,medianandsdbecome their weighted versions (nstays the unweighted base).
Value
A tibble with n (non-missing count), mean,
median and sd, one row per group when by is supplied.
Details
The column is passed through ensure_numeric() first, so a text age column
like "25 years" still summarises. n counts non-missing values (after that
coercion). When a weighting scheme is active the statistics are weighted (and
missing values are dropped); n remains the unweighted respondent count. For a
measure of how precise the mean is, pair this with diagnose() or
se_mean().
See also
calc_percentage() for categorical variables, diagnose() for
precision.
Other summaries:
calc_percentage(),
calc_percentage_batch(),
calc_percentage_multi(),
clear_checkpoints(),
crosstab(),
crosstab_banner()
Examples
calc_summary(podracing_survey, demo_age)
#> # A tibble: 1 × 4
#> n mean median sd
#> <int> <dbl> <dbl> <dbl>
#> 1 1000 32.6 32 11.2
calc_summary(podracing_survey, demo_age, by = region)
#> # A tibble: 5 × 5
#> region n mean median sd
#> <chr> <int> <dbl> <dbl> <dbl>
#> 1 Asia 59 31.9 32 11.0
#> 2 Europe 314 32.9 32 11.0
#> 3 Latin America 82 30.6 31 10.4
#> 4 North America 503 33.2 33 11.5
#> 5 Oceania 42 28.6 27.5 10.2
