0

I am trying to find out the max no of attacks done by gname in each region_text in each year.

iyear  region_text  gname  nkill 
1970   asia         xyz    1      
1970   asia         xyz    1
1970   asia         abc    1
1970   africa       bbb    1
1970   africa       bbb    1
1971   asia         nnn    2
1971   asia         mmm    2
1971   asia         nnn    2
1971   africa       kkk    0

Solution needed

iyear  region_text  gname  nkill  nattacks(new column)
1970   asia         xyz    2      2
1970   africa       bbb    2      2
1971   asia         nnn    2      2
1971   africa       kkk    0      1

I have data for 45 years(1970-2015) divided into 12 regions(asia, africa...)

I have tried aggregate function but it could not tell me the no of attacks grouped by each year instead for all 45 years.
I am a newbie to R, need to know which direction I need to go. Thanks!

multimediadev
  • 155
  • 1
  • 1
  • 7
  • Can you include the code you tried with aggregate? It's likely you're already pretty close to a solution. Also, why is only one `gname` value represented for each year/region combination in your "Solution needed"? – rosscova Nov 20 '16 at 05:24
  • Are you grouping by the first 3 columns? – akrun Nov 20 '16 at 05:24

0 Answers0