# HG changeset patch # User guerler # Date 1397871694 14400 # Node ID e676c441d38877bf1d27489b23cf40e9085e3fff # Parent 9479e62342fae25ea153d815ae45e50e39ef3460 Uploaded diff -r 9479e62342fa -r e676c441d388 histogram.r --- 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)]))