r - Identifying the index number in a group of counts -


i have df need tally , group group. want identify index(?) of observation in grouping.

the group a has 4 observations, want to attach index of 3 3rd a observation.

df %>%  group_by(group) %>%  mutate(count = n())  #   group index count #1         1     4 #2         2     4 #3         3     4 #4         4     4 #5      b    1     1 #6      b    2     1 #7      c    1     3 #8      c    2     3 #9      c    3     3 #10     d    1     1 

you want use window function row_number():

df %>%   group_by(group) %>%   mutate(index = row_number()) # explicit row_number(group) 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -