[R] Gregmisc 'running' question

Sean Davis sdavis2 at mail.nih.gov
Fri Mar 26 15:31:30 CET 2004


Just a quick and probably simple question:

> dat <- rnorm(500,sd=1+(1:500)/500)
> fun <- function(x) t.test(x)$p.value
> running(dat,width=50,fun=fun,allow=T)
Error in t.test.default(x) : not enough x observations
> running(dat,width=50,fun=fun,allow=F)
Error in t.test.default(x) : not enough x observations
> fun2 <- function(x) mean(x)
> running(dat,width=50,fun=fun2,allow=T)
         1:1          1:2          1:3          1:4          1:5
1:6 
-0.334134613 -0.626595581 -0.368967457 -0.113737178 -0.057448771
0.228643936 
         1:7          1:8          1:9         1:10         1:11
1:12 
-0.058807689  0.021762463 -0.063805657  0.031931121  0.080465708
0.087062800 
....

However, this works fine.

> t.test(dat[1:50])$p.value
[1] 0.1661845

Why doesn't t.test work with running here?

Thanks,
Sean




More information about the R-help mailing list