基于优先级/决策的行选择

发布于 2024-10-07 00:16:42 字数 761 浏览 0 评论 0原文

我有一个包含许多重复行的 data.frame,类似于这样:

con <- textConnection(Lines <- "
First, Last, Address, Address 2, Email, Custom1, Custom2, Custom3
A, B, C, D, [email protected],1,2,3
A, B, C, D, [email protected],1,2,2
A, B, C, D, [email protected],1,2,1
")
x <- read.csv(con)
close(con)

现在,当我按以下方式去重复时:

x <- x[!duplicated(x[,c("email")]),]

您能否推荐一种方法来对包含 Custom3=1 的行进行优先级排序?或者有更好的重复数据删除机制吗?

I have a data.frame that has a number of duplicate rows, akin to something like this:

con <- textConnection(Lines <- "
First, Last, Address, Address 2, Email, Custom1, Custom2, Custom3
A, B, C, D, [email protected],1,2,3
A, B, C, D, [email protected],1,2,2
A, B, C, D, [email protected],1,2,1
")
x <- read.csv(con)
close(con)

Now, when I de-duplicate, in the following manner:

x <- x[!duplicated(x[,c("email")]),]

Could you recommend a method for prioritizing those rows that contain Custom3=1? Or is there a better mechanism for de-duplication?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如荒岛 2024-10-14 00:16:42

在查找重复项之前尝试排序:

x <- x[order(x[,c("Custom3")]),]
x <- x[!重复(x[,c("电子邮件")]),]

Try sorting before finding duplicates:

x <- x[order(x[,c("Custom3")]),]
x <- x[!duplicated(x[,c("email")]),]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文