[R] T.test error help
Uwe Ligges
ligges at statistik.tu-dortmund.de
Thu Jul 9 17:59:46 CEST 2009
Daniel Malter wrote:
> put another condition in your loop
>
> if(all.equal(x,y)=TRUE) i=i+1 else t.test...
>
> something in that direction.
Sorry, but that's neither valid R code nor sensible in this case.
See my suggestions below.
> best,
> daniel
>
>
> -------------------------
> cuncta stricte discussurus
> -------------------------
>
> -----Ursprüngliche Nachricht-----
> Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
> Auftrag von Amit Patel
> Gesendet: Thursday, July 09, 2009 9:20 AM
> An: r-help at r-project.org
> Betreff: [R] T.test error help
>
>
> Hi I am implementing the t.test in a loop and where the data is the same i
> get an error message.
>
> Error in t.test.default(Samp3, Samp1, na.rm = TRUE, var.equal = FALSE, :
> data are essentially constant
>
> The script i am using is
>
> for (i in 1:length(zz[,1])) {
for(i in seq_along(zz[,1])){
should be safer.
> Samp1 <- zz[i,2:17]
> Samp2 <- zz[i,18:33]
> Samp3 <- zz[i,34:47]
> Samp4 <- zz[i,48:63]
>
> TTestResult[i,2] <- t.test(Samp2, Samp1, na.rm=TRUE, var.equal = FALSE,
> paired=FALSE, conf.level=0.95)$p.value
>
>
> TTestResult[i,3] <- t.test(Samp3, Samp1, na.rm=TRUE, var.equal = FALSE,
> paired=FALSE, conf.level=0.95)$p.value
>
> TTestResult[i,4] <- t.test(Samp4, Samp1, na.rm=TRUE, var.equal = FALSE,
> paired=FALSE, conf.level=0.95)$p.value
>
> }
>
> Is there a way to make my loop ignore this problem and go onto the next
> iteration
yes, you can wrap it in try() and check the object with
if(inherits(object, "try-error")) later on in order to do something
different (e.g. assign an NA) in case of an error.
Uwe Ligges
>
>
>
>
> ______________________________________________
> 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.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list