c_wmean | R Documentation |
c_wmean() computes the cluster weighted mean for a given variable, and a given clustering variable
c_wmean(x, w, j)
x |
a numeric vector of a single variable |
w |
a numeric vector for within cluster weights |
j |
a numeric vector for clusters index |
simple wrapper for ave(x,j), to estimate cluster means weighted by within cluster weights
a numeric vector
library(dplyr)
library(dplyr)
example_data <- data.frame(
x = c(1,2,3,4,5,6),
w = c(.4,.4,.4,.6,.6,.6),
id_j = c(1,1,1,2,2,2)
)
example_data %>%
mutate(cluster_mean = c_wmean(x, w, id_j)) %>%
select(x, id_j, cluster_mean) %>%
unique() %>%
print
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.