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