comparison histogram.r @ 12:9479e62342fa draft

Uploaded
author guerler
date Fri, 18 Apr 2014 16:40:58 -0400
parents 61a1d67f70d4
children e676c441d388
comparison
equal deleted inserted replaced
11:61a1d67f70d4 12:9479e62342fa
1 # utilities
2 roundUp <- function(x) 10 * ceiling(x/10)
3 roundDown <- function(x) 10 * floor(x/10)
4
5 # wrapper 1 # wrapper
6 wrapper <- function(table, columns, options) { 2 wrapper <- function(table, columns, options) {
7 3
8 # initialize output list 4 # initialize output list
9 l <- list() 5 l <- list()
18 # collect vectors in list 14 # collect vectors in list
19 m <- append(m, list(column_data)) 15 m <- append(m, list(column_data))
20 } 16 }
21 17
22 # get min/max boundaries 18 # get min/max boundaries
19 min_value <- min(unlist(m))
23 max_value <- max(unlist(m)) 20 max_value <- max(unlist(m))
24 min_value <- min(unlist(m))
25
26 # round number to base 10
27 min_value <- roundDown(min_value)
28 max_value <- roundUp(max_value)
29 21
30 # check if single bin is enough 22 # check if single bin is enough
31 if (min_value == max_value) { 23 if (min_value == max_value) {
32 l <- append(l, max_value) 24 l <- append(l, max_value)
33 for (key in seq(m)) { 25 for (key in seq(m)) {
35 } 27 }
36 return (l) 28 return (l)
37 } 29 }
38 30
39 # identify increment 31 # identify increment
40 increment <- roundUp((max_value - min_value) / 10) 32 increment <- (max_value - min_value) / 10
41 33
42 # fix range and bins 34 # fix range and bins
43 bin_seq = seq(min_value, max_value, by=increment) 35 bin_seq = seq(min_value, max_value, by=increment)
44 36
45 # add as first column 37 # add as first column