[R] getting t.test to work with apply()
ONKELINX, Thierry
Thierry.ONKELINX at inbo.be
Mon Jun 4 10:15:26 CEST 2007
Since you are using function(x) the apply function is passing values to
x. So you need to use x inside the function.
Try something like this:
apply(raw.sample,1,function(x){t.test(x["alive"],x["dead"])})
Cheers,
Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be
Do not put your faith in what statistics say until you have carefully
considered what they do not say. ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op stat.math.ethz.ch
> [mailto:r-help-bounces op stat.math.ethz.ch] Namens Andrew Yee
> Verzonden: zondag 3 juni 2007 23:49
> Aan: r-help op stat.math.ethz.ch
> Onderwerp: [R] getting t.test to work with apply()
>
> Hi, I'm interested in using apply() with t.test() on a data.frame.
>
> Specifically, I'd like to use apply() to do the following:
>
> t.test(raw.sample[1,alive],raw.sample[1,dead])
> t.test(raw.sample[2,alive],raw.sample[2,dead])
> t.test(raw.sample[3,alive],raw.sample[3,dead])
> etc.
>
> I tried the following,
>
> apply(raw.sample,1,function(x)
> t.test(raw.sample[,alive],raw.sample[,dead]))
>
> but it gives me a list of identical results.
>
>
> Thanks,
> Andrew
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help op stat.math.ethz.ch 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.
>
More information about the R-help
mailing list