使用一行代码将重复的行删除多个列中的重复行
我有一个数据框架,想一起删除多个列的重复项,它更快且看起来不错。
我尝试了以下操作:
dataframe = dataframe [!duplicated(dataframe [c("Column1", "Column2", "Column3)]),]
使用它,代码在没有错误的情况下运行,但没有任何变化。当我使用dim()
检查时,没有删除行。
当我使用此代码删除重复时,它有效:
dupli = duplicated(dataframe$Column1)
dataframe = dataframe[!dupli,]
dupli = duplicated(dataframe$Column2)
dataframe = dataframe[!dupli,]
dupli = duplicated(dataframe$Column3)
dataframe = dataframe[!dupli,]
现在已删除了重复项。因此,这些列中肯定有重复的内容。那么,与他们一起的代码行有什么问题?
I have a data frame and want to remove duplicates for multiple columns all together, it's faster and looks nice.
I tried this:
dataframe = dataframe [!duplicated(dataframe [c("Column1", "Column2", "Column3)]),]
Using this, the code runs without errors, but nothing changes. No rows are deleted when I check with dim()
.
When I delete duplicates using this code, it works:
dupli = duplicated(dataframe$Column1)
dataframe = dataframe[!dupli,]
dupli = duplicated(dataframe$Column2)
dataframe = dataframe[!dupli,]
dupli = duplicated(dataframe$Column3)
dataframe = dataframe[!dupli,]
Now the duplicates have been deleted. So there are definitely duplicates in these columns. So what's wrong with the line of code with them all together?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论