Skip to content
Prev 267352 / 398502 Next

Errors, driving me nuts

On 08/01/2011 08:47 PM, Matt Curcio wrote:
...an awesome alternative is to use ldply from the plyr package:

library(plyr)
files_to_test <- list.files (pattern = "kegg.combine")
tt_pvalue <- ldply(files_to_test, function(fname) {
    raw_data <- read.table (files_to_test[i], header=TRUE, sep=" ")
    tmpA <- raw_data[,compareA]
    tmpB <- raw_data[,compareB]
    tt <- t.test (tmpA, tmpB, var.equal=TRUE)
    return(data.frame(fname = fname, pvalue = tt$p.value))
}, .progress = TRUE)

This saves you some bookkeeping (no need to create tt_pvalue in advance
and keep track of the iterator (i)) and you get a nice progress bar
(good when loops take long). ldply (and other plyr functions) are what I
use most when processing large amounts of information.

cheers,
Paul