Some (Pseudo-) Random Number Stuff in R
Use runif to make a “vector” of Random numbers with a uniform distribution Uniform means the number is as likely to fall between 0.1 and 0.2 as between 0.5 and 0.6, and so on. As opposed to a normal distribution around of mean of 0.5, then it is more likely to be close to the mean.
Result a vector with 100 “elements” or “components”
Apply some of the statistical methods to the vector.
Using the ifelse() method to turn the uniform numbers into a coin-toss simulation
Another way of simulating a coin toss in R using sample
The table method gets us the frequencies
The replace=TRUE part puts a value back into the set after it is picked. It allows duplications
The replace=FALSE part does not put a value back into the set after it is picked. It prevents duplications
If the range is 1 to 6 and replace=TRUE we have simulated 100 die rolls. Then the table method yields the frequencies
You can make a fast histogram of the die roll simulation by entering hist(dice)
Adding a breaks “argument” a sequence from 0. 5 to 6 Adding a breaks “argument” a sequence from 0.5 to 6.5 made the histogram a little nicer