【发布时间】:2016-04-15 14:44:53
【问题描述】:
样本表:
ID Score1 Score2
1 100 88
1 96 94
1 94 95
2 100 100
2 98 94
3 77 88
所以我希望返回值为 2,因为有 2 个独特的人有一个 Score1 > Score2 的实例。
为了重现性:
df = data.frame( ID=c(1,1,1,2,2,3), Score1=c(100,96,94,100,98,77), Score2=c(88,94,95,100,94,88) )
ID Score1 S
我在想
length( unique( which( df$Score1 > df$Score2 ) ) )
但是返回 3,显然是因为它没有考虑寻找唯一的 df$ID,只是唯一出现的次数。如何解释想要唯一df$ID 的唯一编号?
【问题讨论】:
标签: r data.table unique