annotate histogram.r @ 33:39ee947b4a9e draft

Uploaded
author guerler
date Mon, 07 Apr 2014 19:24:19 -0400
parents 001c5e3e5517
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
1 wrapper <- function(table, columns, options) {
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
2
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
3 # initialize output list
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
4 l <- list()
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
5
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
6 # loop through all columns
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
7 for (key in names(columns)) {
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
8 # load column data
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
9 column <- as.numeric(columns[key])
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
10 column_data <- sapply( table[column], as.numeric )
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
11
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
12 # create hist data
33
39ee947b4a9e Uploaded
guerler
parents: 2
diff changeset
13 hist_data <- hist(column_data, plot=FALSE)
2
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
14
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
15 # collect vectors in list
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
16 l <- append(l, list(hist_data$breaks[2: length(hist_data$breaks)]))
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
17 l <- append(l, list(hist_data$density))
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
18 }
33
39ee947b4a9e Uploaded
guerler
parents: 2
diff changeset
19
39ee947b4a9e Uploaded
guerler
parents: 2
diff changeset
20 # make sure length is fine
39ee947b4a9e Uploaded
guerler
parents: 2
diff changeset
21 n <- max(sapply(l, length))
39ee947b4a9e Uploaded
guerler
parents: 2
diff changeset
22 ll <- lapply(l, function(X) {
39ee947b4a9e Uploaded
guerler
parents: 2
diff changeset
23 c(as.character(X), rep("", times = n - length(X)))
39ee947b4a9e Uploaded
guerler
parents: 2
diff changeset
24 })
39ee947b4a9e Uploaded
guerler
parents: 2
diff changeset
25 l <- do.call(cbind, ll)
2
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
26
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
27 # return
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
28 return (l)
001c5e3e5517 Uploaded
guerler
parents:
diff changeset
29 }