comparison histogram.r @ 13:e676c441d388 draft

Uploaded
author guerler
date Fri, 18 Apr 2014 21:41:34 -0400
parents 9479e62342fa
children
comparison
equal deleted inserted replaced
12:9479e62342fa 13:e676c441d388
1 # utilities
2 boundary <- function(x, increment) {
3 return (floor(x / increment) * increment)
4 }
5
6 roundup <- function(x) {
7 return (sign(x) * 10^ceiling(log10(abs(x))))
8 }
9
1 # wrapper 10 # wrapper
2 wrapper <- function(table, columns, options) { 11 wrapper <- function(table, columns, options) {
3 12
4 # initialize output list 13 # initialize output list
5 l <- list() 14 l <- list()
17 26
18 # get min/max boundaries 27 # get min/max boundaries
19 min_value <- min(unlist(m)) 28 min_value <- min(unlist(m))
20 max_value <- max(unlist(m)) 29 max_value <- max(unlist(m))
21 30
31 # identify increment
32 increment <- roundup((max_value - min_value) / 10)
33
34 # fix min value
35 min_value <- boundary(min_value, increment)
36
37 # fix max value
38 max_value <- min_value + increment * 10
39
22 # check if single bin is enough 40 # check if single bin is enough
23 if (min_value == max_value) { 41 if (min_value == max_value) {
24 l <- append(l, max_value) 42 l <- append(l, max_value)
25 for (key in seq(m)) { 43 for (key in seq(m)) {
26 l <- append(l, 1.0) 44 l <- append(l, 1.0)
27 } 45 }
28 return (l) 46 return (l)
29 } 47 }
30 48
31 # identify increment
32 increment <- (max_value - min_value) / 10
33
34 # fix range and bins 49 # fix range and bins
35 bin_seq = seq(min_value, max_value, by=increment) 50 bin_seq = seq(min_value, max_value, by=increment)
36 51
37 # add as first column 52 # add as first column
38 l <- append(l, list(bin_seq[2: length(bin_seq)])) 53 l <- append(l, list(bin_seq[2: length(bin_seq)]))
39 54
40 # loop through all columns 55 # loop through all columns
41 for (key in seq(m)) { 56 for (key in seq(m)) {