Skip to content

Commit ae3e18a

Browse files
Prevent error 'missing value where TRUE/FALSE needed' if x or y contains Inf.
1 parent 2bd49a8 commit ae3e18a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/library/stats/R/t.test.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function(x, y = NULL, alternative = c("two.sided", "less", "greater"),
6060
if(nx < 2) stop("not enough 'x' observations")
6161
df <- nx-1
6262
stderr <- sqrt(vx/nx)
63-
if(stderr < 10 *.Machine$double.eps * abs(mx))
63+
if(!is.na(stderr) && stderr < 10 *.Machine$double.eps * abs(mx))
6464
stop("data are essentially constant")
6565
tstat <- (mx-mu)/stderr
6666
method <- if(paired) "Paired t-test" else "One Sample t-test"
@@ -91,7 +91,7 @@ function(x, y = NULL, alternative = c("two.sided", "less", "greater"),
9191
stderr <- sqrt(stderrx^2 + stderry^2)
9292
df <- stderr^4/(stderrx^4/(nx-1) + stderry^4/(ny-1))
9393
}
94-
if(stderr < 10 *.Machine$double.eps * max(abs(mx), abs(my)))
94+
if(!is.na(stderr) && stderr < 10 *.Machine$double.eps * max(abs(mx), abs(my)))
9595
stop("data are essentially constant")
9696
tstat <- (mx - my - mu)/stderr
9797
}

0 commit comments

Comments
 (0)