Wasn’t sure how to title this, so please change it 🙂
If I have data like this and I want to trim it such that if there are more than one of any value in V5, then only keep the row with the highest value for V4. So for example, for V5=7200 there is row id 25 and row id 20 but I only want to keep row id 20 because its V4 is higher.
V4 V5
29 9.94 5900
28 10.56 5100
27 11.34 6200
26 11.42 8300
25 13.16 7200
24 13.78 7500
23 14.16 6200
22 14.26 7500
21 14.6 7400
20 14.64 7200
19 15.86 8800
to:
V4 V5
29 9.94 5900
28 10.56 5100
26 11.42 8300
23 14.16 6200
22 14.26 7500
21 14.6 7400
20 14.64 7200
19 15.86 8800
Is there a way to do this in a vectorized fashion or maybe some clever shortcut? If I have to do it for a lot of different matrices it could take a while with simple structures (for loops and the like).
1 Answer