【发布时间】:2021-05-14 18:44:30
【问题描述】:
我有一个看起来像这样的数据集
ID|Type
1 "Basketball"
1 "Baseball"
2 "Basketball"
2 "Football"
3 "Boxing"
4 "Boxing"
4 "Wrestling"
4 "Handball"
4 "Hockey"
我想创建一个如下所示的数据集
ID| Type|observation
1 "Basketball" 1
1 "Baseball" 2
2 "Basketball" 1
2 "Football" 2
3 "Boxing" 1
4 "Boxing" 1
4 "Wrestling" 2
4 "Handball" 3
4 "Hockey" 4
我在这部分之后被卡住并尝试这样做
df %>%
group_by(ID) %>%
1:nrow(df)
【问题讨论】: