0

I would like to combine rows which have the same keys(multiple).

For example, If I have this kind of data:

OD, Itinerary, Passengers

AAA, I, 5

AAA, I, 6

AAA, II, 4

BBB, II, 3

And I would like to combine rows(by adding up "Passengers") whose first two columns are the same, like this:

OD, Itinerary, Passengers

AAA, I, 11

AAA, II, 4

BBB, II, 3

I have tried group_by and summarise. That will do but I wonder whether there is a simpler way to do that.

J.Q.
  • 1
  • 2
  • `aggregate( Passengers~OD + Itinerary ,data,sum)` – Onyambu Jul 31 '18 at 08:05
  • This is a duplicate question. Before you ask a question nsure you have googled how to do your problem first of all – Onyambu Jul 31 '18 at 08:07
  • I did searched and tried many times. My question is a little diffrent from the link you provided because I want to aggregate on two key value instead of one@Ronak Shah. Thanks to @Onyambu that solved my problem. – J.Q. Jul 31 '18 at 08:19
  • A good way in SO is to read the Q/As with many votes: https://stackoverflow.com/questions/tagged/r?sort=votes – jogo Jul 31 '18 at 08:23

0 Answers0