[R] apply, t-test and p-values PREVIOUS SUGGESTION DID NOT WORK
csardi.gabor at gmail.com
Thu Oct 16 18:18:28 CEST 2008
How about the following?
sapply(1:nrow(sample1), function(x) t.test(sample1[x,], sample2[x,])$p.value)
On Thu, Oct 16, 2008 at 6:07 PM, John Sorkin
<jsorkin at grecc.umaryland.edu> 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
> 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
> # Compute t-test comparing second row of sample 1 to second row of sample 2
> # Compute t-test comparing third row of sample 1 to third row of sample 2
> # Compute t-test comparing fourth row of sample 1 to fourth row of sample 2
> 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!
Gabor Csardi <Gabor.Csardi at unil.ch> UNIL DGM
More information about the R-help