[R] newbie question: p.values in a column

Emmanuel Paradis paradis at isem.univ-montp2.fr
Wed Sep 18 16:53:35 CEST 2002


At 07:48 18/09/02 -0500, Hao Chen wrote:
>Hello,
>
>I have a vector (v) with 6 columns and 2000 rows. I am trying to do one 

So v is a matrix (not a vector).

>sample t.test for each row (I know this sounds crazy) and put the 
>p.values into the 7th column.
>
>I know I can access the p.value via t.test(v[i,])[3]$p.value; I know I 

The index `[3]' is useless here. You can use either `[3]' or `$p.value',
but there is a difference between them:

> str(t.test(1:10)[3])
List of 1
 $ p.value: num 0.000278
> str(t.test(1:10)$p.value)
 num 0.000278

>can do t.test on the row by apply(v, 1, t.test), but I just couldn't 
>figure out how to fit them together.

I guess there are several solutions. Here is mine.

N <- nrow(v)
PVAL <- numeric(N)
for (i in 1:N) PVAL[i] <- t.test(v[i, ])$p.value
v <- cbind(v, PVAL)


Hoping this helps.

EP

>I'd very appreciate your help!!
>
>Hao Chen
>
>
>
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
.-.-
>r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
>Send "info", "help", or "[un]subscribe"
>(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
._._
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list