diff histogram.r @ 8:a889861139bc draft

Uploaded
author guerler
date Thu, 17 Apr 2014 17:56:42 -0400
parents 2e2d92b2ae38
children 656efffe650e
line wrap: on
line diff
--- a/histogram.r	Thu Apr 17 17:35:24 2014 -0400
+++ b/histogram.r	Thu Apr 17 17:56:42 2014 -0400
@@ -1,3 +1,8 @@
+# utilities
+roundUp <- function(x) 10^ceiling(log10(x))
+roundDown <- function(x) 10^floor(log10(x))
+
+# wrapper
 wrapper <- function(table, columns, options) {
 
     # initialize output list
@@ -18,8 +23,15 @@
     max_value <- max(unlist(m))
     min_value <- min(unlist(m))
     
+    # round number to base 10
+    min_value <- roundUp(min_value)
+    max_value <- roundUp(max_value)
+    
+    # identify increment
+    increment <- (max_value - min_value) / 10
+    
     # fix range and bins
-    bin_seq = seq(min_value, max_value, by=10)
+    bin_seq = seq(min_value, max_value, by=increment)
 
     # add as first column
     l <- append(l, list(bin_seq[2: length(bin_seq)]))