comparison histogram.r @ 36:524184c2f524 draft

Uploaded
author guerler
date Fri, 09 May 2014 00:59:08 -0400
parents 0e3df2630d9b
children b84a193361be
comparison
equal deleted inserted replaced
35:f294f5c9608c 36:524184c2f524
1 # utilities 1 # binsize
2 boundary <- function(x, increment) { 2 min_binsize = 10
3
4 # lower boundary
5 lowerboundary <- function(x, increment) {
3 return (floor(x / increment) * increment) 6 return (floor(x / increment) * increment)
4 } 7 }
5 8
9 # upper boundary
10 upperboundary <- function(x, increment) {
11 return (ceiling(x / increment) * increment)
12 }
13
14 # round to decimals
6 roundup <- function(x) { 15 roundup <- function(x) {
7 return (sign(x) * 10^ceiling(log10(abs(x)))) 16 return (sign(x) * 10^ceiling(log10(abs(x))))
8 } 17 }
9 18
10 # wrapper 19 # wrapper
11 wrapper <- function(table, columns, options) { 20 wrapper <- function(table, columns, options) {
12 21
22 # get binsize
23 binsize = max(as.integer(options$binsize), min_binsize)
24
13 # initialize output list 25 # initialize output list
14 l <- list() 26 l <- list()
15 27
16 # loop through all columns 28 # loop through all columns
17 m <- list() 29 m <- list()
26 38
27 # get min/max boundaries 39 # get min/max boundaries
28 min_value <- min(unlist(m)) 40 min_value <- min(unlist(m))
29 max_value <- max(unlist(m)) 41 max_value <- max(unlist(m))
30 42
43 # identify range
44 diff <- max_value - min_value
45
31 # identify increment 46 # identify increment
32 increment <- roundup((max_value - min_value) / 10) 47 increment <- roundup(diff / binsize)
33 48
34 # fix min value 49 # fix min value
35 min_value <- boundary(min_value, increment) 50 min_value <- lowerboundary(min_value, increment)
51 max_value <- upperboundary(max_value, increment)
52
53 # update range
54 diff <- max_value - min_value
55
56 # fix bin size
57 binsize = round(diff / increment)
36 58
37 # fix max value 59 # fix max value
38 max_value <- min_value + increment * 10 60 max_value <- min_value + binsize * increment
39 61
40 # check if single bin is enough 62 # check if single bin is enough
41 if (min_value == max_value) { 63 if (min_value == max_value) {
42 l <- append(l, max_value) 64 l <- append(l, max_value)
43 for (key in seq(m)) { 65 for (key in seq(m)) {
68 90
69 # collect vectors in list 91 # collect vectors in list
70 l <- append(l, list(hist_data$counts)) 92 l <- append(l, list(hist_data$counts))
71 } 93 }
72 94
73
74 # return 95 # return
75 return (l) 96 return (l)
76 } 97 }