changeset 0:8fefbbf372be draft

Uploaded
author guerler
date Thu, 17 Apr 2014 11:16:28 -0400
parents
children f2d42848d165
files histogram.r
diffstat 1 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/histogram.r	Thu Apr 17 11:16:28 2014 -0400
@@ -0,0 +1,32 @@
+wrapper <- function(table, columns, options) {
+
+    # initialize output list
+    l <- list()
+
+    # loop through all columns
+    for (key in names(columns)) {
+        # load column data
+        column <- as.numeric(columns[key])
+        column_data <- sapply( table[column], as.numeric )
+
+        # create hist data
+        hist_data <- hist(column_data, plot=FALSE)
+        
+        # normalize densities
+        hist_data$counts=hist_data$counts/sum(hist_data$counts)
+
+        # collect vectors in list
+        l <- append(l, list(hist_data$breaks[2: length(hist_data$breaks)]))
+        l <- append(l, list(hist_data$counts))
+    }
+    
+    # make sure length is fine
+    n <- max(sapply(l, length))
+    ll <- lapply(l, function(X) {
+        c(as.character(X), rep("", times = n - length(X)))
+    })
+    l <- do.call(cbind, ll)
+
+    # return
+    return (l)
+}