英文:
how to show the duplicates of column 'a' with different values for column 'b'
问题
你的问题是这样的,我需要在R中确定具有不同结果的相同变体。所以我有:
变体 | 结果 |
---|---|
1 | A |
1 | A |
1 | A |
1 | B |
2 | C |
2 | C |
2 | C |
3 | D |
3 | E |
4 | F |
4 | F |
4 | F |
4 | G |
4 | G |
5 | H |
5 | H |
5 | H |
5 | H |
而我的输出应该是:
变体
1,
3,
& 4
英文:
My problem is as follows, I need to determine the same variants with a different outcome in R.
So I have:
Variant | Outcome |
---|---|
1 | A |
1 | A |
1 | A |
1 | B |
2 | C |
2 | C |
2 | C |
3 | D |
3 | E |
4 | F |
4 | F |
4 | F |
4 | G |
4 | G |
5 | H |
5 | H |
5 | H |
5 | H |
And my output should be:
Variant
1,
3,
& 4
I know about the functions duplicated, intersect etc but have no clue how to combine them to get what I want.
答案1
得分: 1
基础 R 解决方案:
with(df, df[ave(Outcome, Variant, FUN = function(x) length(unique(x))) >= 2, ])
Variant Outcome
1 1 A
2 1 A
3 1 A
4 1 B
8 3 D
9 3 E
10 4 F
11 4 F
12 4 F
13 4 G
14 4 G
<details>
<summary>英文:</summary>
Base R solution:
with(df, df[ave(Outcome, Variant, FUN = function(x) length(unique(x))) >= 2, ])
Variant Outcome
1 1 A
2 1 A
3 1 A
4 1 B
8 3 D
9 3 E
10 4 F
11 4 F
12 4 F
13 4 G
14 4 G
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论