ASP.NET / C# / Math: Remove Extreme Numbers from Array

How can I automatically remove all extreme numbers from an array?

For example,
double[] y = {23.2542, 24.25356, 21.89, 25.345, 24.237, 29.2325, 1.52, 99.234, 26.234, 2.53342, 104.2343 };

Open in new window

These numbers are extreme compared to the other numbers in the array:
1.52,
99.234
2.53342
104.2343

A person can look at the numbers in the array and notice that those are extremes, however I would like to use ASP.NET/C# to identify and remove the extreme numbers.
LVL 10
skijAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Stephen CalabreseCommented:
You could calculate the standard deviation.  Then any values that are +- 2 standard deviations, you can remove from the list.
private double getStandardDeviation(List<double> doubleList)  
{  
   double average = doubleList.Average();  
   double sumOfDerivation = 0;  
   foreach (double value in doubleList)  
   {  
      sumOfDerivation += (value) * (value);  
   }  
   double sumOfDerivationAverage = sumOfDerivation / (doubleList.Count - 1);  
   return Math.Sqrt(sumOfDerivationAverage - (average*average));  
}  

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skijAuthor Commented:
Thank you, Stephen.  I have posted a related question here:
0
Stephen CalabreseCommented:
Hi skij, I don't see the realted question!
0
skijAuthor Commented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.