Aggregate multiple rows of the same data.frame in R based on common values in given columns
aggregate(value ~ item + size + weight, FUN = mean, data=df)
item size weight value
1 B 1 2 3
2 C 3 2 1
3 A 2 3 5
Here is the solution using the ddply
from plyr package:
library(plyr)
ddply(df,.(item),colwise(mean))
item size weight value
1 A 2 3 5
2 B 1 2 3
3 C 3 2 1
df$value <- ave(df$value,df$item,FUN=mean)
df[!duplicated(df$item),]
item size weight value
1 A 2 3 5
3 B 1 2 3
4 C 3 2 1