Saturday, April 12, 2014

Generate a series of random numbers

I'm back, and now am the proud possessor of a doctorate!  I have a really quick post for now, and soon should get a much longer post up on functions, loops, and canonical correlation.

If you want to generate a series of random integers, you can use the sample function.

sample(10, 20, replace=FALSE)
#The first number is how many items you want to end up with
#Here we want 10 random numbers.
#The second number is the number of items to choose from.
#Here we sample out of the integers 1-20.
#replace=FALSE sets it so that we sample without replacement.
#If you draw 6, for example, you won't get 6 again.
#If you set both numbers to be the same thing, you get all the numbers
#in your series drawn in a random order.

No comments:

Post a Comment

Comments and suggestions welcome.