Message-ID: <8D934154-3BFE-4FA6-914B-3887426A553F@gmail.com>
Date: 2007-11-08T22:47:09Z
From: Charilaos Skiadas
Subject: [R-gui] runif function
In-Reply-To: <4733423F.2030803@ualr.edu>
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