基于优先级/决策的行选择
我有一个包含许多重复行的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在查找重复项之前尝试排序:
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")]),]