Hello Listserve,

Here is another question to keep you on your toes. Please consider the following toy dataset:

a <- read.table(textConnection("fred sam joe alex
measure.1 10 4 10 1
measure.2 10 4 2 8
measure.3 3 1 8 3
measure.4 5 1 3 3
measure.5 8 6 8 3
measure.6 9 5 1 0
measure.7 4 6 10 1
measure.8 3 6 8 9
measure.9 8 6 7 7
measure.10 7 8 9 8"), header = TRUE)

And also please consider this toy dataset:
b <- read.table(textConnection("x y
test.1 fred sam
test.2 sam joe
test.3 joe alex"), header = TRUE)

What I want to do is perform some Student's t-tests. The comparisons I want to make are specified in the dataset called "b" -- I'd like to test fred versus sam, sam versus joe, and joe versus alex. How could I use the dataset called "b" to specify the columns to use in the series of t-tests? Keep in mind that my real dataset is enormous (1000 columns) and will likely change, so solutions relying on numeric indexing would not work for me.

I'm thinking the code would look something like this:

#create a matrix for the output
results <- matrix(nrow = nrow(b), ncol = 1)
results <- cbind(b, results)

for (i in 1:length(b)){
    results[i,3] <- t.test(???, ???) #this is where I'm stuck. How do I pull the information I want out of b -- i.e., the columns to use -- to do the appropriate comparisons?
}

I'm hoping for a solution that doesn't create any new subsetted matrices along the way, because this will slow down the run time.

Thanks in advance,
Josh


      
	[[alternative HTML version deleted]]

