0

I have a table in R in following format :

    Name        Place      Num 
     Name_A     Place_1    231
     Name_A     Place_1    232
     Name_A     Place_2    233
     Name_A     Place_2    432
     Name_A     Place_2    433
     Name_X     Place_1    534
     Name_X     Place_1    535

For every Name and Place cols ,Num col is sorted and Continuous. I just want to change the Num col start from 1 and increment continously for every pair of Name and Place . Desired Output for above table :

      Name        Place      Num 
     Name_A     Place_1    1
     Name_A     Place_1    2
     Name_A     Place_2    1
     Name_A     Place_2    2
     Name_A     Place_2    3
     Name_X     Place_1    1
     Name_X     Place_1    2

Not here for loop soln. Any help appreciated.

learner
  • 11
  • 3

1 Answers1

1
library(dplyr)
Data %>%
   group_by(Name,Place) %>%
   mutate(Num=row_number())
akrun
  • 874,273
  • 37
  • 540
  • 662
adaien
  • 1,932
  • 1
  • 12
  • 26