[R] t.test() on a list

Gang Chen gangchen6 at gmail.com
Tue Oct 7 20:34:04 CEST 2008


Thanks a lot, Petr! This works perfect!

myList was actually a list of data.frame, and the command line
initially choked. But once I converted it to matrix, it worked like a
charm:

apply(do.call(rbind, lapply(lapply(myList, as.matrix), c)), 2, t.test)

Thanks,
Gang


On Mon, Oct 6, 2008 at 9:42 AM, Petr PIKAL <petr.pikal at precheza.cz> wrote:
> Hi
>
> maybe not an answer you like but
>
> apply(do.call(rbind, lapply(myList, c)), 2, t.test)
>
> shall give you desired results
>
> Regards
> Petr
>
>
> r-help-bounces at r-project.org napsal dne 02.10.2008 23:25:23:
>
>> I appreciate your suggestion. The example I provided was fabricated
>> because I was only focusing on the programming perspective on how to
>> deal with such a data structure, not real statistical issues. Do you
>> mind elaborating a little more why that would not be appreciate? I
>> know I can do it with a couple of loops,  but I still appreciate
>> suggestions on how to write a line or two to run t-tests on such a
>> data structure.
>>
>> Thanks,
>> Gang
>>
>>
>> On Thu, Oct 2, 2008 at 5:11 PM, Bert Gunter <gunter.berton at gene.com>
> wrote:
>> > I am sure you will get helpful answers. I am almost as sure that you
>> > shouldn't be doing this. I suggest you consult with your local
> statistician.
>> >
>> > -- Bert Gunter
>> >
>> > -----Original Message-----
>> > From: r-help-bounces at r-project.org [
> mailto:r-help-bounces at r-project.org] On
>> > Behalf Of Gang Chen
>> > Sent: Thursday, October 02, 2008 11:24 AM
>> > To: r-help at stat.math.ethz.ch
>> > Subject: [R] t.test() on a list
>> >
>> > I have a list, myList, with each of its 9 components being a 15X15
>> > matrix. I want to run a t-test across the list for each component in
>> > the matrix. For example, the first t-test is on myList[[1]][1, 1],
>> > myList[[2]][1, 1], ..., myList[[9]][1, 1]; and there are totally 15X15
>> > t-tests. How can I run these t-tests in a simple way?
>> >
>> > TIA,
>> > Gang



More information about the R-help mailing list