[英]Check value of one column based on another R
Say I have a dataframe说我有一个数据框
Name <- c("Jon", "Jon", "Maria", "Maria", "Tina", "Tina")
Score <- c(23, 23, 32, 32, 26, 78)
df <- data.frame(Name, Score)
I would like to see if the Score column is the same or different per name.我想看看每个名称的分数列是相同还是不同。 In theory, I expect the score for each column to be the same per name, but it could be the case that they're different (like with Tina) and I would like to check.
理论上,我希望每个名称的每列得分相同,但可能是它们不同(例如 Tina),我想检查一下。
What might be an efficient way to do this?什么可能是一种有效的方法来做到这一点? (My dataframe has over 150 000 rows).
(我的数据框有超过 150 000 行)。
Try this to get the counts, then you can check if Name is duplicated试试这个来获得计数,然后你可以检查名称是否重复
library(magrittr)
library(dplyr)
df %>%
count(Name, Score)%>%
add_count(Name, name = "name_n")%>%
filter(name_n > 1)
#output
Name Score n name_n
1 Tina 26 1 2
2 Tina 78 1 2
would this help ?这会有帮助吗?
> df %>% count(Name, Score) %>% filter(n<2)
Name Score n
1 Tina 26 1
2 Tina 78 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.