getGroups: Determine groups and group means

View source: R/utilities.R

getGroupsR Documentation

Determine groups and group means

Description

Splits a continuous variable into n groups (either equidistant or with equal number of observations) and returns the group mean for every observation.

Usage

getGroups(x, n = NULL, equidistant = FALSE)

Arguments

x

Numeric vector to be split.

n

Desired number of groups. If NULL, the function chooses roughly one group per 100 observations, constrained to 3 \le n \le 20.

equidistant

If TRUE, intervals have equal width; otherwise (default) each interval contains roughly the same number of observations.

Value

Numeric vector of the same length as x with the group mean assigned to each observation.

Examples

## Not run: 
x <- rnorm(1000, mean = 50, sd = 10)
m <- getGroups(x, n = 10)

## End(Not run)

cNORM documentation built on July 20, 2026, 5:07 p.m.