comparison histogram.r @ 5:cbdd329ab623 draft

Uploaded
author guerler
date Thu, 17 Apr 2014 12:45:29 -0400
parents 8fefbbf372be
children 6a11aeb8bd39
comparison
equal deleted inserted replaced
4:b079b17dcb4a 5:cbdd329ab623
11 11
12 # create hist data 12 # create hist data
13 hist_data <- hist(column_data, plot=FALSE) 13 hist_data <- hist(column_data, plot=FALSE)
14 14
15 # normalize densities 15 # normalize densities
16 hist_data$counts=hist_data$counts/sum(hist_data$counts) 16 count_sum <- sum(hist_data$counts)
17 if (count_sum > 0) {
18 hist_data$counts=hist_data$counts/count_sum
19 }
17 20
18 # collect vectors in list 21 # collect vectors in list
19 l <- append(l, list(hist_data$breaks[2: length(hist_data$breaks)])) 22 l <- append(l, list(hist_data$breaks[2: length(hist_data$breaks)]))
20 l <- append(l, list(hist_data$counts)) 23 l <- append(l, list(hist_data$counts))
21 } 24 }
22 25
23 # make sure length is fine 26 # make sure length is fine
24 n <- max(sapply(l, length)) 27 n <- max(sapply(l, length))
25 ll <- lapply(l, function(X) { 28 ll <- lapply(l, function(X) {
26 c(as.character(X), rep("", times = n - length(X))) 29 c(as.character(X), rep('undefined', times = n - length(X)))
27 }) 30 })
28 l <- do.call(cbind, ll) 31 l <- do.call(cbind, ll)
29 32
30 # return 33 # return
31 return (l) 34 return (l)