title: dplyr: Generate row number/row position in group_by
body: <p>I have a dataset and I want to generate the row position by group. For example</p>
  
  <pre><code>library(data.table)
  
  data&lt;-data.table(Position=c(1,2,3,4,5,6,7,8,9,10),
  Category=c("M","M","M","M","F","F","F","M","M","F"))
  </code></pre>
  
  <p>I group by the Category and want to create column that is the row position by group. Something like below or with data.table</p>
  
  <pre><code>dataByGroup %&gt;% group_by(Category) %&gt;% mutate(positionInCategory = 1:nrow(Category))
  </code></pre>
  
  <p>Unable to work out how to achieve this? </p>
  
  <p>Desired output: </p>
  
  <pre><code>| Position|Category | positionInCategory|
  |--------:|:--------|------------------:|
  |        1|M        |                  1|
  |        2|M        |                  2|
  |        3|M        |                  3|
  |        4|M        |                  4|
  |        5|F        |                  1|
  |        6|F        |                  2|
  |        7|F        |                  3|
  |        8|M        |                  5|
  |        9|M        |                  6|
  |       10|F        |                  4|
  </code></pre>