Skip to content

Instantly share code, notes, and snippets.

@d2fn
Created October 1, 2010 03:28
Show Gist options
  • Save d2fn/605676 to your computer and use it in GitHub Desktop.
Save d2fn/605676 to your computer and use it in GitHub Desktop.
partition set of numbers into subsets of equal size
def equibin(a:Seq[Double], depth:Int) = {
val d = a.size/depth
(0 until a.size) // ordered set of indexes of all values
.groupBy(i=>i/d).values.toList.sortBy(s=>s(0)) // split set into 'd' separate lists
.map { group => group.map( i => a(i) ) } // map onto value set
.map { values => ( (min(a),max(a)), values ) }// each bin gets min-max metadata
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment