Skip to content

Errors, driving me nuts

3 messages · Matt Curcio, Ista Zahn, Paul Hiemstra

#
Greetings all,
I am getting this error that is driving me nuts... (not a long trip, haha)

I have a set of files and in these files I want to calculate ttests on
rows 'compareA' and 'compareB' (these will change over time there I
want a variable here). Also these files are in many different
directories so I want a way filter out the junk...  Anyway I don't
believe that this is related to my errors but I mention it none the
less.
+    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)
+    tt_pvalue[i] <- tt$p.value
+ }
Error in tt_pvalue[i] <- tt$p.value : object 'tt_pvalue' not found
# I tried setting up a vector...
# as.vector(tt_pvalue, mode="any") ### but NO GO
Error in inherits(x, "data.frame") : object 'tt_pvalue' not found
# No idea??

What is going wrong??
M


Matt Curcio
M: 401-316-5358
E: matt.curcio.ri at gmail.com
#
Hi Matt,
On Mon, Aug 1, 2011 at 4:47 PM, Matt Curcio <matt.curcio.ri at gmail.com> wrote:
you need to create tt_pvalue before you can assign values to it (i.e.,
before you start your for-loop). Consider this simpler example:

tst[1] <- 1
Error in tst[1] <- 1 : object 'tst' not found
tst <- vector()
tst[1] <- 1

Best,
Ista

  
    
#
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