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