Hello, I have a vector (v) with 6 columns and 2000 rows. I am trying to do one 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 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'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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Why not specify a function in your apply statement? v[,7] <- apply(v, 1, function(row) t.test(row)[3]$p.value) Good luck. Kevin -----Original Message----- From: Hao Chen [mailto:hchen at utmem.edu] Sent: Wednesday, September 18, 2002 8:48 AM To: r-help at stat.math.ethz.ch Subject: [R] newbie question: p.values in a column Hello, I have a vector (v) with 6 columns and 2000 rows. I am trying to do one 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 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'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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 oneSo 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 IThe 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Remington.Richard@epamail.epa.gov
2002-Sep-18 15:55 UTC
[R] newbie question: p.values in a column
Hao Using some fake data, here's a crude way to get the job done for 2 rows temp <- matrix( runif(2*6, -2, 2), nrow=2) out <- apply( temp, 1, t.test) temp <- data.frame( temp, p.value=unlist(out)[ names( unlist( out)) == "p.value"]) temp Richard Remington Hao Chen wrote> > Hello, > > I have a vector (v) with 6 columns and 2000 rows. I am trying to doone> 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> 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'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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hao Chen wrote:> > Hello, > > I have a vector (v) with 6 columns and 2000 rows. I am trying to do one > 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 > 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'd very appreciate your help!!Whether it makes sense or not to perform a t.test() of your 6 numbers ... I guess v is a matrix. In that case: # calculate the t.test() and extract p-values for each row: tt <- apply(v, 1, function(x) t.test(x)$p.value) # put the tt values in a new column: v <- cbind(v, tt) Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I assume v is a matrix (not a vector)? If so, try new.v <- cbind(v, apply(v, 1, function(x) t.test(x)$p.value)) This should produce a 2000 x 7 matrix with the p-values in the 7th column. -roger _______________________________ UCLA Department of Statistics rpeng at stat.ucla.edu http://www.stat.ucla.edu/~rpeng On Wed, 18 Sep 2002, Hao Chen wrote:> Hello, > > I have a vector (v) with 6 columns and 2000 rows. I am trying to do one > 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 > 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'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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Reasonably Related Threads
- win.metafile on linux?
- [PATCH] virtio_net: set default mtu to 1500 when 'Device maximum MTU' bigger than 1500
- The two chisq.test p values differ when the contingency table is transposed! (PR#3486)
- [LLVMdev] A Java version of LLVM Core for LLVM IR Analysis: JLLVM
- [LLVMdev] A Java version of LLVM Core for LLVM IR Analysis: JLLVM