changeset 13:e676c441d388 draft

Uploaded
author guerler
date Fri, 18 Apr 2014 21:41:34 -0400
parents 9479e62342fa
children 61421ea8a3d4
files histogram.r
diffstat 1 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/histogram.r	Fri Apr 18 16:40:58 2014 -0400
+++ b/histogram.r	Fri Apr 18 21:41:34 2014 -0400
@@ -1,3 +1,12 @@
+# utilities
+boundary <- function(x, increment) {
+    return (floor(x / increment) * increment)
+}
+
+roundup <- function(x) {
+    return (sign(x) * 10^ceiling(log10(abs(x))))
+}
+
 # wrapper
 wrapper <- function(table, columns, options) {
 
@@ -19,6 +28,15 @@
     min_value <- min(unlist(m))
     max_value <- max(unlist(m))
     
+    # identify increment
+    increment <- roundup((max_value - min_value) / 10)
+    
+    # fix min value
+    min_value <- boundary(min_value, increment)
+    
+    # fix max value
+    max_value <- min_value + increment * 10
+    
     # check if single bin is enough
     if (min_value == max_value) {
         l <- append(l, max_value)
@@ -28,12 +46,9 @@
         return (l)
     }
     
-    # identify increment
-    increment <- (max_value - min_value) / 10
-    
     # fix range and bins
     bin_seq = seq(min_value, max_value, by=increment)
- 
+    
     # add as first column
     l <- append(l, list(bin_seq[2: length(bin_seq)]))