r - Sum values of combinations within a group -
for analysis transform data from: data <- data.frame( customer = c("a", "a", "b", "b", "c", "c", "c"), product = c("x", "y", "x", "z", "x", "y", "z"), value = c(10, 15, 5, 10, 20, 5, 10) ) data # customer product value # 1 x 10 # 2 y 15 # 3 b x 5 # 4 b z 10 # 5 c x 20 # 6 c y 5 # 7 c z 10 to: product product sum value -------|-------|--------- x |y |50 x |z |45 y |z |15 basically want sum of value every product combination within customer. guess work of reshape package cannot work. thanks time. here 1 way, in 2 steps: 1) transform data long data.frame of pairs within customers. that, rely on combn provide indices of possible pairs: process.one <- function(x) { n...