data.table tag rows that have no duplicate values within a column
Solution 1:
Try:
d_in_small[,outlier:=if (.N==1) 'outlier',by=score]
Note that the example dataset you provide has only outliers because of the last decimals.
You could group by round(score,decimals)
to get the precision you want to detect outliers.
For example:
d_in_small[,outlier:=if (.N==1) 'outlier',by=round(score,4)][]
score group outlier
<num> <char> <char>
1: 94.27216 a <NA>
2: 94.75169 a outlier
3: 106.58827 a outlier
4: 109.36186 a outlier
5: 111.01705 a outlier
6: 113.70302 a <NA>
7: 118.63886 a outlier
8: 124.00742 a outlier
9: 125.69527 a outlier
10: 125.69639 a outlier
11: 94.27216 a <NA>
12: 94.75165 a outlier
13: 95.49664 a outlier
14: 108.90200 a outlier
15: 113.70303 a <NA>