删除除上次实例以外的所有重复项 [英] Remove all duplicates except last instance

查看:123
本文介绍了删除除上次实例以外的所有重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在R中有一个数据集,其布局如下:

So I have a dataset in R with the following layout as an example:

ID Date Tally
1 2/1/2011 1
2 2/1/2011 2
3 2/1/2011 3
1 2/1/2011 4
2 2/1/2011 5
1 2/1/2011 6
3 2/1/2011 7
4 2/1/2011 8
2 2/1/2011 9

我想删除除帖子ID的LAST实例之外的所有实例。现在我可以在网上找到的所有东西,我使用的功能是删除除FIRST实例之外的所有内容。

I want to remove all instances except the LAST instance of the post id. Right now everything I can find online, and functions I am using is removing everything except the FIRST instance.

所以我的新数据框将如下所示:

So my new data frame would look like:

ID Date Tally
1 2/1/2011 6
3 2/1/2011 7
4 2/1/2011 8
2 2/1/2011 9

我该怎么做?现在我只能保留一审。我想要做相反的事情?任何帮助?

How do I do this? Right now I am only able to keep the first instance. I want it to do the opposite? Any help?

与我同在,我是新来的R:)

Bear with me I am new to R :)

推荐答案

使用!rev(duplicate(rev(ID)))可过滤除最后一次唯一出现之外的所有内容。

Use !rev(duplicated(rev(ID))) to filter out all but the last unique occurrences.

要获取数据集过滤,请使用 dataset [!rev(duplicate(rev(dataset $ ID)))],]

To get the dataset filtered, use dataset[!rev(duplicated(rev(dataset$ID))),]

这篇关于删除除上次实例以外的所有重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆