[R-sig-Debian] set.seed
Dirk Eddelbuettel
edd at debian.org
Sat Mar 26 05:33:07 CET 2011
On 26 March 2011 at 00:30, Biau David wrote:
| Dear list,
|
| It looks like set.seed does not work for me (see code below). I am running
| Debian squeeze. Is this an issue with the distribution or with my understanding
| of the function? I'm pretty sure, but not certain, it used to work that way on
| windows
|
| > runif(5)
| [1] 0.6516557 0.5677378 0.1135090 0.5959253 0.3580500
| > runif(5)
| [1] 0.42880942 0.05190332 0.26417767 0.39879073 0.83613414
| > set.seed(15)
| > runif(5)
| [1] 0.6021140 0.1950439 0.9664587 0.6509055 0.3670719
| > runif(5)
| [1] 0.9888592 0.8151934 0.2539684 0.6872308 0.8314290
|
| Any help would be appreciated. Thx,
You need to set the seed, then draw -- then re-seed and re-draw:
R> set.seed(42); runif(3); rnorm(3)
[1] 0.0161408 0.0922721 0.5505511
[1] -1.0898031 -0.0143024 0.5808842
R> set.seed(42); runif(3); rnorm(3)
[1] 0.0161408 0.0922721 0.5505511
[1] -1.0898031 -0.0143024 0.5808842
R> runif(3); rnorm(3)
[1] 0.623570 0.854190 0.420727
[1] -0.246359 0.195088 0.160348
R>
Identical when I fix the seed, not when I don't. Makes sense?
Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the R-SIG-Debian
mailing list