1

I have an IList<double> and i'm trying to find the most frequent value inside the list, as well as the frequency of each of the numbers on the list, but how would it work in a way that I get something like an IDictionary<number, frequency> of each value?

Thanks :)

5
  • Did you try any code for it ..??
    – Rohit
    Sep 19, 2015 at 14:30
  • 1
    Note that comparing double values is inherently tricky - are you sure that values you might consider to be "kinda equal" will actually be exactly equal?
    – Jon Skeet
    Sep 19, 2015 at 14:31
  • I was trying comparing each value of the list with all the other values, but that way i would compare it with itself and all the duplicates too, would compare with all the other duplicates, and it would not work right, it should group the duplicates and the frequency of the value in a dictionary. Sep 19, 2015 at 14:36
  • And no, the double value should only be equal when it is exactly the same, no aproximations. Sep 19, 2015 at 14:37
  • A similar question is answered here: stackoverflow.com/questions/21733278/…
    – Sivaraj
    Sep 19, 2015 at 14:41

1 Answer 1

4
var dictionary= list.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.