cluster_means: Compute cluster means

View source: R/cluster_means.R

cluster_meansR Documentation

Compute cluster means

Description

This function computes the mean of a single or a range of specified variable/s within each cluster.

Usage

cluster_means(data, .cols, .id_cluster, .suffix = "_cl")

Arguments

data

A data frame.

.cols

<data-masked> The name/s or column number/s of the numeric variable/s for which cluster means should be computed.

.id_cluster

<data-masked> The name or column number of the identifier for the clusters within which means should be computed.

.suffix

Optional. A string to be added to the original variable name/s to label the new column/s for the cluster means. The default is the suffix "_cl".

Value

An tibble containing the new cluster means indicated by the suffix specified in .suffix.

Examples

# Compute cluster means at the school level for mathematics
cluster_means(data = studach, .cols = math, .id_cluster = id_sch, .suffix = "_sch")

# Compute cluster means at the classroom level for mathematics and reading
cluster_means(data = studach, .cols = math:read, .id_cluster = id_cla, .suffix = "_cla")

sophiestallasch/multides documentation built on Oct. 20, 2024, 5:14 a.m.