R: How to add a dummy variable for counting the number of appearance

时间:2018-11-27 00:55:00

标签: r count

Here is my dataframe:

Number    Action
1         Running
2         Running
3         Swimming
4         Eating
5         Eating

I would like to add a variable to count the number of appearance, like this:

Number    Action    Count
1         Running   1
2         Running   2
3         Swimming  1
4         Eating    1
5         Eating    2

1 个答案:

答案 0 :(得分:0)

这是使用memcmp

的一种方法
dplyr

reprex package(v0.2.1)于2018-11-26创建