# HG changeset patch # User guerler # Date 1399611524 14400 # Node ID f92f6839902328686e1b6548a4c53ad7a7f99be3 # Parent 83555a70c34c6283e153c850c4a46f0828b37d9d Uploaded diff -r 83555a70c34c -r f92f68399023 histogramdiscrete.r --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogramdiscrete.r Fri May 09 00:58:44 2014 -0400 @@ -0,0 +1,54 @@ +# wrapper +wrapper <- function(table, columns, options) { + + # initialize output list + l <- list() + + # loop through all columns + m <- list() + for (key in names(columns)) { + # load column data + column <- as.numeric(columns[key]) + + # ensure string column + column_data <- sapply( table[column], as.character ) + + # collect vectors in list + m <- append(m, list(column_data)) + } + + # get alphabetically sorted bins + bins <- sort(unique(unlist(m))) + + # add first column + l <- append(l, list(bins)) + + # loop through all columns + for (key in seq(m)) { + # reset bins + bins = sapply(bins, function(v) { 0 }) + + # load column data + column_data <- m[[key]] + + # create hist data + table_data <- table(column_data) + + # transfer counts to bins + for (id in names(table_data)) { + bins[id] <- table_data[id] + } + + # normalize densities + total <- length(column_data) + if (total > 0) { + bins = bins / total + } + + # collect vectors in list + l <- append(l, list(bins)) + } + + # return + return (l) +}