Skip to contents

Counts the respondents behind each dependent variable – those with a value for it and for indep, if given – and returns the count as a string, or the smallest and largest count when the dependent variables differ.

With mesos_var and mesos_group the count is that of the target group, as makeme() draws it for crowd = "target". Set crowd to count the others, or everyone, instead.

Usage

n_range(
  data,
  dep,
  indep = NULL,
  mesos_var = NULL,
  mesos_group = NULL,
  crowd = NULL,
  glue_template_1 = "{n}",
  glue_template_2 = "[{n[1]}-{n[2]}]"
)

Arguments

data

Dataset

dep, indep

Tidyselect syntax

mesos_var

Optional, NULL or string specifying name of variable used to split dataset.

mesos_group

Optional, NULL or string specifying value in mesos_var indicating the target group.

crowd

NULL (default) or a string, one of "all", "target" or "others": whose rows to count. "target" counts the rows where mesos_var equals mesos_group, "others" the rows where it does not, and "all" every row whatever mesos_var and mesos_group are. NULL means "target" when mesos_group is given and "all" when it is not. "target" and "others" need both mesos_var and mesos_group.

glue_template_1, glue_template_2

String, for the case of a single value (1) or a range with minimum-maximum of values (2).

Value

String.

Examples

n_range(data = ex_survey, dep = b_1:b_3, indep = x1_sex)
#> 300

# The target group, and everyone else
n_range(
  data = ex_survey, dep = b_1:b_3,
  mesos_var = "f_uni", mesos_group = "Uni of A"
)
#> 66
n_range(
  data = ex_survey, dep = b_1:b_3,
  mesos_var = "f_uni", mesos_group = "Uni of A", crowd = "others"
)
#> 234