使用一行代码将重复的行删除多个列中的重复行

发布于 2025-02-13 09:38:15 字数 544 浏览 0 评论 0原文

我有一个数据框架,想一起删除多个列的重复项,它更快且看起来不错。

我尝试了以下操作:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文