# HG changeset patch # User guerler # Date 1397771802 14400 # Node ID a889861139bc518a0c7723592d347b74ad1c5ea2 # Parent 2e2d92b2ae38046051e5408da673da8345e9160c Uploaded diff -r 2e2d92b2ae38 -r a889861139bc histogram.r --- 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)]))