Lets say I have a list of numbers:
val numbers = List(15, 30, 110, 140, 170, 210)
How can I count the number of integers per bin of a 100
in order to get:
Map(0 -> 2, 100 -> 3, 200 -> 1)
// val items = List(1, 2, 3, 101, 330, 302)
items.groupBy(i => i/100).map { case (i, l) => (i*100, l.length) }
// Map(100 -> 1, 300 -> 2, 0 -> 3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With