Learn R Programming

sjmisc (version 1.0.3)

group_labels: Create labels for recoded groups

Description

Creates the related labels for the grouped variable created by group_var.

Usage

group_labels(var, groupsize = 5, rightInterval = FALSE,
  autoGroupCount = 30)

Arguments

var
numeric variable, which should recoded into groups.
groupsize
group-size, i.e. the range for grouping. By default, for each 5 categories new group is built, i.e. groupsize = 5. Use groupsize = "auto" to automatically resize a variable into a maximum of 30 groups (which is the ggplot-default
rightInterval
logical; if TRUE, grouping starts with the lower bound of groupsize. If FALSE (default), grouping starts with the upper bound of groupsize. See 'Examples' and 'Details'.
autoGroupCount
Sets the maximum number of groups that are built when auto-grouping is on (groupsize = "auto"). Default is 30. If groupsize is not set to "auto", this parameter will be ignored.

Value

  • A string vector containing labels based on the grouped categories of var, formatted as "from lower bound to upper bound", e.g. "10-19" "20-29" "30-39" etc. See examples below.

Details

See 'Details' in group_var.

See Also

Examples

Run this code
age <- abs(round(rnorm(100, 65, 20)))
age.grp <- group_var(age, 10)
hist(age)
hist(age.grp)

age.grpvar <- group_labels(age, 10)
table(age.grp)
print(age.grpvar)


# create vector with values from 50 to 80
dummy <- round(runif(200, 50, 80))
# labels with grouping starting at lower bound
group_labels(dummy)
# labels with grouping startint at upper bound
group_labels(dummy, rightInterval = TRUE)


# histogram with EUROFAMCARE sample dataset
# variable not grouped
data(efc)
hist(efc$e17age, main = get_var_labels(efc$e17age))

# bar plot with EUROFAMCARE sample dataset
# grouped variable
ageGrp <- group_var(efc$e17age)
ageGrpLab <- group_labels(efc$e17age)
barplot(table(ageGrp),
        main = get_var_labels(efc$e17age),
        names.arg = ageGrpLab)

Run the code above in your browser using DataLab