我一直在为一款网球游戏开发一个带有滚动球的数据集.我试图找到最后5名球员留在替补席上,但还有另一列球员互换位置.这导致了一个问题,因为玩家可以在最后5行转出,然后再转出,所以我不能简单地使用tail(5).因此,如果球员换回来,那么实际上她并不是替补席上的最后一个.下面是一个数据框,包含最后8个值.
sub_off | sub_on | time |
---|---|---|
Alexia | Jorja | 750 |
Amy | Sophie | 770 |
Jorja | Cassandra | 800 |
Lucy | Jane | 820 |
Claire | Khloe | 820 |
Cassie | Alexia | 850 |
Khloe | Claire | 890 |
Georgia | Khloe | 895 |
请注意,我想挑选留在板凳上的5名球员.他们是乔治亚、卡西、露西、乔哈和艾米.这是因为科勒、克莱尔和亚历克西亚替补在比赛后期复出.
In other words, I want to pick the last 5 values in the sub_off column that don't appear in the rows following for the sub_on column.
df <- data.frame(
sub_off = c('Alexia', 'Amy', 'Jorja', 'Lucy', 'Claire', 'Cassie', 'Khloe', 'Georgia'),
sub_on = c('Jorja', 'Sophie', 'Cassandra', 'Jane', 'Khloe', 'Alexia', 'Claire', 'Khloe'),
time = c(750, 770, 800, 820, 820, 850, 890, 895)
)
df
这是数据框,如果您有任何帮助,我们将不胜感激.谢谢