I have a dataframe with different parameters in each. I'll like to merge rows using a different set of parameters for each row. Here is my sameple data ZZ:
ZZ<-data.frame(Name =c("A","B","C","D","E","F"),A1=c(19,20,21,23,45,67),A2=c(1,2,3,4,5,6),A3=c(7,8,13,24,88,90),x=c(4,5,6,8,23,16),y=c(-3,-7,-6,-9,3,2))
> ZZ
Name A1 A2 A3 x y
1 A 19 1 7 4 -3
2 B 20 2 8 5 -7
3 C 21 3 13 6 -6
4 D 23 4 24 8 -9
5 E 45 5 88 23 3
6 F 67 6 90 16 2
I want to aggregate the rows A,B,C and D,E,F such that a new name is defined for each group (eg:C1 and C2), A1,A2 and A3 are combined by sum while x and y using the mean.
How can this be done please? The result should be:
> ZZ2
Name A1 A2 A3 x y
1 C1 60 6 28 5.000 -5.333
2 C2 135 15 202 15.667 -1.333