如何显示具有不同列’b’值的列’a’的重复项

huangapple go评论137阅读模式
英文:

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>



huangapple
  • 本文由 发表于 2023年3月12日 19:33:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712831.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定