comparison histogramdiscrete.r @ 0:a87a3773d8ed draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 87080d49913cfd40a77eda7e5834ac9c4bc30b0b
author iuc
date Fri, 09 Mar 2018 08:23:08 -0500
parents
children 344ac3ca7557
comparison
equal deleted inserted replaced
-1:000000000000 0:a87a3773d8ed
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 <- as.character(table[column][[1]])
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 }