[R] Performing a function on columns specified in another dataframe

From: Josh B <joshb41_at_yahoo.com>
Date: Wed, 09 Jun 2010 12:04:19 -0700 (PDT)


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]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 Jun 2010 - 19:58:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jun 2010 - 20:30:53 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive