How about the following? sapply(1:nrow(sample1), function(x) t.test(sample1[x,], sample2[x,])$p.value)
Gabor On Thu, Oct 16, 2008 at 6:07 PM, John Sorkin <[EMAIL PROTECTED]> wrote: > Although I am grateful to Jorge and David for their suggestions, their > solution will not solve my problem as sample2 is not fixed. Let me > demonstrate what I want to do: > > > # Define two matricies > sample1<-matrix(data=c(1:20),byrow=TRUE,ncol=5,nrow=4) > sample2<-sample1+rnorm(20) > > These are the computations that I would like to perform using apply (or some > similar method): > > > # Compute t-test comparing first row of sample 1 to first row of sample 2 > t.test(sample1[1,],sample2[1,]) > > # Compute t-test comparing second row of sample 1 to second row of sample 2 > t.test(sample1[2,],sample2[2,]) > > # Compute t-test comparing third row of sample 1 to third row of sample 2 > t.test(sample1[3,],sample2[3,]) > > # Compute t-test comparing fourth row of sample 1 to fourth row of sample 2 > t.test(sample1[4,],sample2[4,]) > > > > As you can see, the code below does not return the same values! It does not > work. > apply(sample1,1,function(x) t.test(x,sample1)$p.value) > > Sugestions would be appreciated! > John > [...] -- Gabor Csardi <[EMAIL PROTECTED]> UNIL DGM ______________________________________________ R-help@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.