Dear all, I'm a bit confused about the output from functions that generates random values, e.g. rpois. I'm using 0.65.1 on Digital UNIX alphaev6. If I say> rpois(10,5)output is not unexpectedly: [1] 4 6 5 7 6 5 2 2 5 3 but I figured that if I go:> rpois(10,1:10)I would get a 10x10 matrix as output, with random values for each of the vector elements in the row vectors, but I'm getting [1] 3 4 3 4 6 9 10 6 11 9 so, that is obviously not the case... :-) BTW, what am I getting...? So, I went on to thinking that> outer(10, 1:10, rpois)would do the trick, but no.... Again, what am I getting? So, is there a simple way of doing this...? If not, would it be reasonable for me to request this as a feature in future releases? Best, Kjetil -- Kjetil Kjernsmo Graduate astronomy-student Problems worthy of attack University of Oslo, Norway Prove their worth by hitting back E-mail: kjetikj at astro.uio.no - Piet Hein Homepage <URL:http://www.astro.uio.no/~kjetikj/> Webmaster at skepsis.no -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Kjetil Kjernsmo <kjetil.kjernsmo at astro.uio.no> writes:> but I figured that if I go: > > rpois(10,1:10) > I would get a 10x10 matrix as output, with random values for each of > the vector elements in the row vectors, but I'm getting > [1] 3 4 3 4 6 9 10 6 11 9 > so, that is obviously not the case... :-) BTW, what am I getting...?try plot(rpois(100,1:100)) and I think you'll see the light...> So, is there a simple way of doing this...? If not, would it be reasonable > for me to request this as a feature in future releases?matrix(rpois(100,rep(1:10,10)),10,byrow=T) should do it. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "Kjetil" == Kjetil Kjernsmo <kjetil.kjernsmo at astro.uio.no> writes:Kjetil> Dear all, I'm a bit confused about the output from functions Kjetil> that generates random values, e.g. rpois. I'm using 0.65.1 on Kjetil> Digital UNIX alphaev6. Kjetil> If I say >> rpois(10,5) Kjetil> output is not unexpectedly: [1] 4 6 5 7 6 5 2 2 5 3 Kjetil> but I figured that if I go: >> rpois(10,1:10) Kjetil> I would get a 10x10 matrix as output, with random values for Kjetil> each of the vector elements in the row vectors, but I'm getting Kjetil> [1] 3 4 3 4 6 9 10 6 11 9 so, that is obviously not the Kjetil> case... :-) BTW, what am I getting...? one for each lambda. There is argument "recycling".. One could argue that R should issue a warning here, but it *is* completely S compatible... Maybe this shows better what happens: > round(rnorm(4, m=c(0,100), sd = c(1e-4,1,10)),2) [1] 0.00 100.77 10.80 100.00 i.e. (m,s) are (0,"0"), (100,1), (0,10), and (100,"0") ------ Kjetil> So, I went on to thinking that >> outer(10, 1:10, rpois) Kjetil> would do the trick, but no.... Again, what am I getting? This was almost correct: > outer(rep(10,10), 1:10, rpois) would have done the job. To see more clearly what happens, rather use outer( rep(10,8), 1+2*(0:9), rpois) Note that AFAIK there are no (?) functions in R (or S) that inherently do "outer". The general principle rather is "recycling". Regards: Martin -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._