I'm trying to perform a simple summarize operation using a trimmed mean by referencing a trim-value column. I keep getting length errors and I cannot understand why this is not working. Maybe I'm missing something obvious?
I don't need any special aggregation, just grouping by one column. All the reference values are the same for each group. I've also tried grouping by both columns (the group and reference columns), but still get the same error.
library(dplyr)
d <- data.frame(
grp = c("a", "a", "a", "b", "b", "b"),
val = seq(1, 16, 3),
ref = c(0.1, 0.1, 0.1, 0.2, 0.2, 0.2)
)
d %>%
group_by(grp) %>%
summarize(m = mean(val, trim = ref))
Error: Evaluation error: 'trim' must be numeric of length one.