I have a list of pairs, for example like this:
list = {{1, 1.1}, {1.00001, 1.1000001}, {2, 1}}
I would like to delete a pair which is lies within a certain range of a previous pair (comparing the first element of each pair would be enough). So I would like somehow to implement a SameTest for the first element of each pair.
In my example the first two pairs should be consideres the same and one of them should be deleted. So my wished output would be:
{{1, 1.1}, {2, 1}}
I tried to use Union and DeleteDuplicates with a SameTest, but they only work if I flatten the list, but I would like to keep the structure.
Then I tried
DeleteDuplicatesBy[list, First]
with works fine (keeps the structure), but it only works if the elements of the list are exactly the same.
I failed to combine a SameTest with DeleteDuplicatesBy.
Is there any neat way to do this?
Edit: note that I have a list of pairs
DeleteDuplicatesBy[list, Round@*First]? – Kuba Feb 19 '16 at 10:55delDuplicates[ list_, rd_:0.1 ] := DeleteDuplicatesBy[ list, Round[ First @ #, rd ]&? – gwr Feb 19 '16 at 10:59delDuplicates[ ]function you can specifyrdto do this, e.g.delDuplicates[ list, 0.0001 ]- is that what you want? – gwr Feb 19 '16 at 11:02Firstand go withUnionor whatever method you want. Although I'm not an expert and don't know which method would be better where I will go now ;-) – Kuba Feb 19 '16 at 11:14p DeleteDuplicatesBy[list/p, Round@*First]wherepis e.g.10^4. – Coolwater Feb 19 '16 at 13:20