0
$\begingroup$

I'm not very good at math but I need to know how to get a set of numbers that are closest to each other.

It means that if I have 5 numbers [-1, 2, 7, 11, 3222]. Now it is obvious (to me) without any rules to see that correct numbers would be -1, 2, 7, 11 or even -1, 2, 7. However I have no idea how to implement some kind of rule that will allow programatically filter a set of numbers and get viable ones.

You can clearly see that simple solutions like calculating median from all numbers and then getting closest numbers to it would be wrong.
Maybe if I would take median of all numbers except 3222, calculate median, get all numbers from set that are +10/-10 it would work well, however, how do I make computer know that 3222 does not belong here...

So basically I'm pretty stuck here. As I said I'm not very good with math so don't judge me by asking this silly question.

  • 0
    What exactly is your definition of "closest" here? I do not really see a pattern in your example, except "the differences are small"...2012-03-20
  • 2
    I would recommend posting to the statistics website to ask "how do I recognize the outliers in a given data set?"2012-03-20
  • 0
    What sequences are you looking at ... what are - in your model of "closeness" - the closest numbers in $[1,2,3, 1000, 1001, 1002]$, the median ansatz doesn't fit well here.2012-03-20
  • 0
    @JohannesKloos Well I would say that closest ones are the ones who are in rage of +50 and -50. Like in example that I wrote - if I take away `3222`, calculate average of the ones who are left and than take everything from set that is +50 and -50 I would have a viable array.2012-03-20
  • 0
    @martini yes, I didn't see that. Too bad, however in my data sets there is only 1-3 numbers that are so big compared to others. So if I ignore this problem is it still possible?2012-03-20
  • 0
    @GerryMyerson Thanks for advice, will do.2012-03-20
  • 0
    Would something like [bucket sort](http://en.wikipedia.org/wiki/Bucket_sort) help here? Perhaps not directly. But might give some useful ideas?2012-03-20

1 Answers 1