Session Ready
Exercise

Flipping an unfair coin

Until now you've been running simulations where each outcome had an equal probability. However, the sample() function also allows you to set the probabilities.

You can set these probabilities by adding an argument called prob to the sample() function. This argument needs a vector of probability weights, one for each possible outcome. An example of such a vector for three possible outcomes is c(0.1, 0.6, 0.3).

Note that for the fair coin the probability weight vector is c(0.5, 0.5). The default of the sample() function (when no prob is given) is for all outcomes to have equal probability.

Instructions
100 XP
  • Run 100 simulations of an unfair coin that lands on head 20% of the time. Do this by assigning assign the result to sim_unfair_coin. (If you need help, look at the documentation by typing ?sample in the console.)
  • Inspect the result using the table() function.