[R] vector argument to rnorm

John Aitchison jaitchis at lisp.com.au
Sat Mar 3 08:54:13 CET 2001


Is this intended behaviour ?

> length(rnorm(c(100)))
[1] 100
> length(rnorm(c(100,0,1)))
[1] 3
> length(rnorm(length(c(100,1,2))))
[1] 3
> length(rnorm(c(100,0,1,2,3,4,5)))
[1] 7

ie if you pass in a single element vector the first element of that is 
taken as the desired n (OK) , but otherwise the length of the vector 
argument is taken as the desired n.

I came across this usage in an example for terasvirta.test (same for 
white.test) in tseries

> example(terasvirta.test)

trsvr.> n <- 1000
trsvr.> x <- runif(1000, -1, 1)
trsvr.> y <- x^2 - x^3 + 0.1 * rnorm(x)
trsvr.> terasvirta.test(x, y)

and it seemed to me that rnorm(n) was what was intended, not that it would 
make any difference in practice in this case.

Is this a standard practice? .. that in passing in a vector where a scalar 
is expected it is as if you passed in the length of that vector as the 
argument (unless the vector has length 1)
 

John Aitchison
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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