I'm looking for a way to do essentially what the rowsum function does, except take the product instead of the sum.
Let's say I have the matrix a and a vector of grouping IDs group:
a <- matrix(seq(12), ncol = 2)
group <- c(1, 1, 2, 2, 3, 3)
I can get the sums of each row by group using rowsum(a, group):
rowsum(a, group)
[,1] [,2]
1 3 15
2 7 19
3 11 23
How could I get the product of each row by group, which would give:
[,1] [,2]
1 2 56
2 12 90
3 30 132