c_median: c_median() computes the cluster median for given variable,...

View source: R/c_median.R

c_medianR Documentation

c_median() computes the cluster median for given variable, and a given clustering variable

Description

c_median() computes the cluster median for given variable, and a given clustering variable

Usage

c_median(x, j)

Arguments

x

a numeric vector of a single variable

j

a numeric vector that indexes values into groups

Details

simple wrapper for 'ave(variable, group)' function, to estimate cluster means

Value

a numeric vector

Examples

example_data <- data.frame(x = c(1,2,3,4,5,6), j = c(1,1,1,2,2,2))
library(dplyr)
example_data %>%
mutate(cluster_median =  c_median(x, j)) %>%
select(x, j) %>%
unique() %>%
print

dacarras/r4sda documentation built on Nov. 9, 2023, 10:17 a.m.