Skip to contents

Takes one numeric variable and returns a tidy dataframe, including relative mean and absolute size of each group. The variable can be further segmented by another categorical variable. Can also take survey weights. Returns 95% confidence intervals.

Usage

stem_summarise_num(
  data,
  item,
  group = NULL,
  weight = NULL,
  long = FALSE,
  collapse_group = NULL,
  return_n = FALSE
)

Arguments

data

Dataframe including data to be analyzed

item

Variable to be summarised

group

Optional segmenting variable

weight

Optional survey weights

long

Returns data in long format. Useful if multiple dataframes are to be merged

collapse_group

Named list. Optionally collapses (or renames) categories of the group variable

return_n

If TRUE, returns absolute group sizes.

Value

Tidy dataframe

Examples

trust |> stem_summarise_num(age,
                            group = eu_index,
                            weight = W,
         collapse_group = list(`Neutral or no opinion` = c("Neutral", "Doesn't Know")))
#> # A tibble: 3 × 6
#>   eu_index              group_n item_n  mean mean_low mean_upp
#>   <fct>                   <int>  <int> <dbl>    <dbl>    <dbl>
#> 1 Likes EU                  365    365  39.2     38.7     39.6
#> 2 Neutral or no opinion     423    423  39.0     38.5     39.4
#> 3 Dislikes EU               212    212  38.2     37.5     38.9