Learn R Programming

cNORM (version 3.6.1)

getGroups: 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)

Value

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

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.

Examples

Run this code
if (FALSE) {
x <- rnorm(1000, mean = 50, sd = 10)
m <- getGroups(x, n = 10)
}

Run the code above in your browser using DataLab