34
|
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
|
|
13 # ensure string column
|
|
14 column_data <- sapply( table[column], as.character )
|
|
15
|
|
16 # collect vectors in list
|
|
17 m <- append(m, list(column_data))
|
|
18 }
|
|
19
|
|
20 # get alphabetically sorted bins
|
|
21 bins <- sort(unique(unlist(m)))
|
|
22
|
|
23 # add first column
|
|
24 l <- append(l, list(bins))
|
|
25
|
|
26 # loop through all columns
|
|
27 for (key in seq(m)) {
|
|
28 # reset bins
|
|
29 bins = sapply(bins, function(v) { 0 })
|
|
30
|
|
31 # load column data
|
|
32 column_data <- m[[key]]
|
|
33
|
|
34 # create hist data
|
|
35 table_data <- table(column_data)
|
|
36
|
|
37 # transfer counts to bins
|
|
38 for (id in names(table_data)) {
|
|
39 bins[id] <- table_data[id]
|
|
40 }
|
|
41
|
|
42 # normalize densities
|
|
43 total <- length(column_data)
|
|
44 if (total > 0) {
|
|
45 bins = bins / total
|
|
46 }
|
|
47
|
|
48 # collect vectors in list
|
|
49 l <- append(l, list(bins))
|
|
50 }
|
|
51
|
|
52 # return
|
|
53 return (l)
|
|
54 }
|