8
|
1 # utilities
|
|
2 roundUp <- function(x) 10^ceiling(log10(x))
|
|
3 roundDown <- function(x) 10^floor(log10(x))
|
|
4
|
|
5 # wrapper
|
0
|
6 wrapper <- function(table, columns, options) {
|
|
7
|
|
8 # initialize output list
|
|
9 l <- list()
|
|
10
|
|
11 # loop through all columns
|
7
|
12 m <- list()
|
0
|
13 for (key in names(columns)) {
|
|
14 # load column data
|
|
15 column <- as.numeric(columns[key])
|
|
16 column_data <- sapply( table[column], as.numeric )
|
|
17
|
7
|
18 # collect vectors in list
|
|
19 m <- append(m, list(column_data))
|
|
20 }
|
|
21
|
|
22 # get min/max boundaries
|
|
23 max_value <- max(unlist(m))
|
|
24 min_value <- min(unlist(m))
|
|
25
|
8
|
26 # round number to base 10
|
|
27 min_value <- roundUp(min_value)
|
|
28 max_value <- roundUp(max_value)
|
|
29
|
|
30 # identify increment
|
|
31 increment <- (max_value - min_value) / 10
|
|
32
|
7
|
33 # fix range and bins
|
8
|
34 bin_seq = seq(min_value, max_value, by=increment)
|
7
|
35
|
|
36 # add as first column
|
|
37 l <- append(l, list(bin_seq[2: length(bin_seq)]))
|
|
38
|
|
39 # loop through all columns
|
|
40 for (key in seq(m)) {
|
|
41 # load column data
|
|
42 column_data <- m[[key]]
|
|
43
|
0
|
44 # create hist data
|
7
|
45 hist_data <- hist(column_data, breaks=bin_seq, plot=FALSE)
|
0
|
46
|
|
47 # normalize densities
|
5
|
48 count_sum <- sum(hist_data$counts)
|
|
49 if (count_sum > 0) {
|
7
|
50 hist_data$counts = hist_data$counts / count_sum
|
5
|
51 }
|
0
|
52
|
|
53 # collect vectors in list
|
|
54 l <- append(l, list(hist_data$counts))
|
|
55 }
|
|
56
|
|
57
|
|
58 # return
|
|
59 return (l)
|
|
60 }
|