« R2jags: Bayesian Hierarchical Modeling in R | Main | Find information about R with Rseek.org »

February 11, 2009

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a010534b1db25970b01116858b134970c

Listed below are links to weblogs that reference How to choose a random number in R:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

great, really helpful. Is there a way to give the random numbers a mean? (ideally with a normal distribution as well). These functions don't seem to have arguments that can do that.

Cheers! Joel.

@Joel: read the relevant help pages carefully. The arguments of rnorm() are n [# of values to pick], mean (default 0) and sd (1). If you want uniform deviates with a specified mean, you have to know that mean = (max+min)/2 and go from there ...

thank you! very clear.

Thank you! This helped me more to learn R!

Thanks :D

thanks. helped me a lot. well explained

Algorithm A1. Central limit theorum method. (Generates a single value, X).
1. For i = 1 to 12:
(a) Generate Ui uniform(0; 1)
2. Let X =sum(random numbers i)-6
3. Deliver X

Is this correct?
r<-function(x,y){
z<- 1:12
x<-runif(z)
sum(x)-6
}
r(1,2)

i have generated a sample of 100items but i wish to create sub-samples of these items of length 5 starting from zero to five. i tried
sample(c(runif(100, min=0, max=5)), size=5, replace=T) but is definitely obtaining only a single sample. i wish to obtain 100 subsamples of size five from the pseudorandom sample of 100 earlier generated

Thank you for posting this! Looking to see if you have one that generates column headers.

Assume there are 5 variables: x,y,z,q,w.

Assume you want to assign 2000 obs to each of the variables above. Hence: 5*2000 = 10000 obs.

Then the way to perform this in R is:
> a10000data<-as.vector(runif(10000))
> x<-a10000data[1:2000]
> y<-a10000data[2001:4000]
> z<-a10000data[4001:6000]
> q<-a10000data[6001:8000]
> w<-a10000data[8001:10000]

I do not know whether these assignments can be performed at once or not. Anyway, my above code is just one way. Though it would be best if we learn from R community how one-step assignment is done for 5 variables.

Erdogan CEVHER
The Ministry of Science, Industry and Technology of Turkey

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment


R for the Enterprise

Got comments or suggestions for the blog editor?
Email David Smith.
Follow revodavid on Twitter Follow David on Twitter: @revodavid

Search Revolutions Blog