[R-gui] runif function
Charilaos Skiadas
cskiadas at gmail.com
Thu Nov 8 23:47:09 CET 2007
On Nov 8, 2007, at 12:07 PM, shweta wrote:
> Hi ,
>
> I was trying to generate random data in R using the runif function.
> But
> I am not sure how do I combine the x and y to get a 2d array/matrix
> in a
> variable z.
> As seen below I am getting the same numbers in x as 1 and in y as 2.1
> respectively. I would like to get different & random numbers in x & y.
>
> Please let me know.
Looking at ?runif, you can see that the syntax for runif is: runif(n,
min=0, max=1)
So when you call runif(N,1), what you really call is runif
(N,min=1,max=1), so you are asking R to generate random numbers
between 1 and 1. Of course they will all be equal to 1. Try runif(N),
or specify both a min and a max.
PS: Not sure what this has to do with GUI though, isn't that more
appropriate to R-help instead of r-sig-gui?
> x <- array(runif(N,1),dim=c(N,1))
>> x
> [,1]
> [1,] 1
> [2,] 1
> [3,] 1
> [4,] 1
> [5,] 1
> [6,] 1
> [7,] 1
> [8,] 1
> [9,] 1
> [10,] 1
>> y <- array(2*x + runif(N,1)/10)
>> y
> [1] 2.1 2.1 2.1 2.1 2.1 2.1 2.1 2.1 2.1 2.1
>
> Thanks & Regards,
> Shweta.
Haris Skiadas
Department of Mathematics and Computer Science
Hanover College
More information about the R-SIG-GUI
mailing list