2

I have data in form of:

data={{1,1,3},{1,1,6},{2,1,7},{2,2,4},{2,1,1}};

I want to match the entries with the same first two elements and add the third element in matching entries, so the result would be:

result={{1,1,9},{2,1,8},{2,2,4}}

For now, this is accomplished by using matching rules, like this:

data//.{h___, {x_, y_, z_}, b___, {x_, y_, f_}, t___} :> {h, {x, y, z + f}, b, t};

Needless to say, the procedure gets painfully slow with lists longer than a few hundred entries. I'm trying to come up with faster alternatives, I already looked at the examples with 1 matching element, but I can't quite expand it to two elements as I'm still fairly unfamiliar with all the operators and procedures.

Regards, blairo

blairo
  • 71
  • 5

0 Answers0