Learn R Programming

sjmisc (version 1.2)

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, right.interval = FALSE, groupcount = 30,
  rightInterval, autoGroupCount)

Arguments

var
Numeric; variable, which should recoded into groups.
groupsize
Numeric; group-size, i.e. the range for grouping. By default, for each 5 categories of var a new group is defined, i.e. groupsize=5. Use groupsize = "auto" to automatically resize a variable into a maximum of 30 grou
right.interval
Logical; if TRUE, grouping starts with the lower bound of groupsize. See 'Details'.
groupcount
Sets the maximum number of groups that are defined when auto-grouping is on (groupsize="auto"). Default is 30. If groupsize is not set to "auto", this argument will be ignored.
rightInterval
deprecated; use right.interval instead
autoGroupCount
deprecated; use groupcount instead

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, right.interval = TRUE)


# histogram with EUROFAMCARE sample dataset
# variable not grouped
data(efc)
hist(efc$e17age, main = get_label(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_label(efc$e17age),
        names.arg = ageGrpLab)

Run the code above in your browser using DataLab