Index: trunk/tools/wsor/message_templates/R/R_helper_functions.R |
— | — | @@ -203,11 +203,11 @@ |
204 | 204 | # Constructs a concatenated data.frame from files |
205 | 205 | # |
206 | 206 | |
207 | | -build.data.frames <- function(template_indices, fname_first_part, fname_last_part, string_frames=c(0)) { |
208 | | - |
| 207 | +build.data.frames <- function(template_indices, fname_first_part, fname_last_part, home_dir, string_frames=c(0)) { |
| 208 | + |
209 | 209 | # Initialize the data frame |
210 | 210 | |
211 | | - filename <- paste(fname_first_part, template_indices[1], fname_last_part, sep="") |
| 211 | + filename <- paste(home_dir, fname_first_part, template_indices[1], fname_last_part, sep="") |
212 | 212 | metrics = read.table(filename, na.strings="\\N", sep="\t", comment.char="", quote="", header=T) |
213 | 213 | output <- paste("Processing data from",filename,"....") |
214 | 214 | print(output) |
— | — | @@ -216,11 +216,15 @@ |
217 | 217 | |
218 | 218 | if (length(template_indices) > 1) |
219 | 219 | for (i in 2:length(template_indices)) |
220 | | - { |
221 | | - |
| 220 | + { |
222 | 221 | index <- template_indices[i] |
223 | | - filename <- paste(fname_first_part, index, fname_last_part, sep="") |
224 | 222 | |
| 223 | + # Make an exception for the "0" template |
| 224 | + if (index == 0) |
| 225 | + filename <- paste(home_dir, "output/metrics_z", index, fname_last_part, sep="") |
| 226 | + else |
| 227 | + filename <- paste(home_dir, fname_first_part, index, fname_last_part, sep="") |
| 228 | + |
225 | 229 | output <- paste("Processing data from",filename,"....") |
226 | 230 | print(output) |
227 | 231 | |
— | — | @@ -299,3 +303,21 @@ |
300 | 304 | new_list |
301 | 305 | } |
302 | 306 | |
| 307 | + |
| 308 | +# FUNCTION :: counts.to.samples |
| 309 | +# |
| 310 | +# Take a list of counts and produce a new list of samples with the same distribution of those counts |
| 311 | +# |
| 312 | + |
| 313 | +counts.to.samples <- function(sample_values, counts) { |
| 314 | + |
| 315 | + samples <- c() |
| 316 | + |
| 317 | + for (i in sample_values) |
| 318 | + { |
| 319 | + samples_to_add <- i * (1:counts[i] / 1:counts[i]) |
| 320 | + samples <- c(samples, samples_to_add) |
| 321 | + } |
| 322 | + |
| 323 | + samples |
| 324 | +} |