Re: [R] t-test for multiple variables

From: Henning Wildhagen <HWildhagen_at_gmx.de>
Date: Fri, 18 Jul 2008 13:07:24 +0200

Hi Simon,

i tried your code, but it results in an error:

"error in var(x) : `x` is empty"

Do you have an idea what the reason might be?

Thanks a lot,

Henning

>
> -------- Original-Nachricht --------
> Datum: Fri, 18 Jul 2008 11:37:24 +0100
> Von: Simon Anders <anders_at_ebi.ac.uk>
> An: Henning Wildhagen <HWildhagen_at_gmx.de>
> CC: r-help_at_r-project.org
> Betreff: Re: [R] t-test for multiple variables
>
> Hi Henning,
>
> Henning Wildhagen wrote:
> > Given a dataframe of three columns, where col1 is of type factor, col 2
> and
> > col3 are numeric and pairs of observations i would like to perform a
> paired
> > t-test for each level of col1.
> > I would like to avoid specifying the levels of col1 manually because it
> > seems to me as being stupid, however, i did not figure out how to tell
> it R
> > in an function. I tried with tapply, but it did not work.
>
> That's what 'tapply' is meant for. Try this:
>
> tapply( 1:nrow(df), df$col1, function(r)
> t.test( df$col2[r], df$col3[r], paired=TRUE ) )
>
> Here, tapply calls the fucntion in the second line for each level of
> col1, always passing the row indices of the rows with this level as
> parameter 'r'.
>
> HTH
> Simon
>
        

-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 


	[[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 Fri 18 Jul 2008 - 11:15:03 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 Sat 19 Jul 2008 - 11:31:45 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