knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(FinalProject)

Flip a Coin - Heads or Tails?

Will it be heads? Or will it be tails?

This is a simple function designed to simulate flipping a 2-sided coin. It takes a random sample from a vector of 1:2.

Examples

When you enter rcoin() into the terminal, it returns one of the possible numbers:

set.seed(777)
rcoin()
rcoin()
rcoin()

If you really want to have fun with it, try making a decision-maker:

#Choose Heads or Tails
CoinDecider <- function(choice){
  flip <- rcoin()
  coin <- ifelse(flip==choice,1,0)
  coin <- ifelse(choice %in% c("Heads","Tails"),coin,2)
  if(coin==1){
    Outcome <- c("You win! Now you can make the house out of pizza")
  }else if(coin==0){
    Outcome <- c("You lose! I suppose you'll have to make the house out of healthy snacks now")
  }else {
    Outcome <- c("You didn't pick correctly!  That means the house will be made out of fishsticks")
  }
  return(list(c(choice,flip),Outcome))
}

set.seed(782)
CoinDecider("Heads")
CoinDecider("Tails")
CoinDecider("Bacon")

This is a great function you can make with rcoin() if you ever need to decide what to make your edible house out of!



labarreb/FinalProject documentation built on May 3, 2019, 1:34 p.m.