I have a data.frame
that looks like this:
# set example data
df <- read.table(textConnection(\"item\\tsize\
Nowadays, this is what I would do:
library(dplyr)
df %>%
group_by(item, size, weight) %>%
summarize(value = mean(value)) %>%
ungroup
This yields the following result:
# A tibble: 3 x 4
item size weight value
1 A 2 3 5
2 B 1 2 3
3 C 3 2 1
I will leave the accepted answer as such as I specifically asked for aggregate
, but I find the dplyr
solution the most readable.