23
|
1 # wrapper
|
|
2 wrapper <- function(table, columns, options) {
|
|
3
|
|
4 # initialize output list
|
|
5 l <- list()
|
|
6
|
|
7 # loop through all columns
|
|
8 m <- list()
|
|
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
|
|
14 # collect vectors in list
|
|
15 m <- append(m, list(column_data))
|
|
16 }
|
|
17
|
45
|
18 # identify optimal breaks
|
|
19 hist_data <- hist(unlist(m), plot=FALSE)
|
|
20 breaks <- hist_data$breaks;
|
23
|
21
|
|
22 # add as first column
|
45
|
23 l <- append(l, list(breaks[2: length(breaks)]))
|
23
|
24
|
|
25 # loop through all columns
|
|
26 for (key in seq(m)) {
|
|
27 # load column data
|
|
28 column_data <- m[[key]]
|
|
29
|
|
30 # create hist data
|
45
|
31 hist_data <- hist(column_data, breaks=breaks, plot=FALSE)
|
23
|
32
|
|
33 # normalize densities
|
|
34 count_sum <- sum(hist_data$counts)
|
|
35 if (count_sum > 0) {
|
|
36 hist_data$counts = hist_data$counts / count_sum
|
|
37 }
|
45
|
38
|
23
|
39 # collect vectors in list
|
|
40 l <- append(l, list(hist_data$counts))
|
|
41 }
|
|
42
|
|
43 # return
|
|
44 return (l)
|
|
45 }
|