In quite a few simulations, we need to generate random numbers. R has a compre-
hensive library of functions to do this. Use runif to generate multiple random num-
bers uniformly between two numbers. Have a look at the following example:
runif(1, 2, 3)
runif(10, 5.0, 7.5)
Of course, every time you get a different number. The sample function generates an
integer random number between numbers:
sample(1:10, 5, replace=T)
The first argument is a vector of valid numbers to generate (here, the numbers are
1 to 10), the second argument indicates numbers to be returned, and the third argu-
ment states that once a number is generated, R can still use that number in future
generations. So, a true there means you may see the same random number more
than once. The default is replace=F . In such cases, there will not be a repetition.
The most basic data type in R and is called a Vector .
The following commands show a set of interesting operations on vectors: