title: Monte Carlo simulation in R for Monty Hall problem not working?
body: <p>I'm writing a function in R to perform a Monte Carlo simulation for the Monty Hall problem. The function is working when the doors are not switched it <code>switch == FALSE</code>, but when I call <code>mean(replicate(10000, monty_hall(switch = TRUE)))</code>, the expected answer is about <code>0.66</code> but I actually get around <code>0.25</code>.</p>
  
  <p>Here is the code to the function:</p>
  
  <pre><code>monty_hall = function(switch = logical()){
      doors &lt;- c(1,2,3)
      names(doors) &lt;- rep(c("goat", "car"), c(2,1))
      prize_door &lt;- doors[3]
  
      guess &lt;- sample(doors, 1)
      revealed_door &lt;- sample(doors[!doors %in% c(guess, prize_door)],1)
      if(switch){
          switched_door &lt;- sample(doors[!doors %in% c(guess, revealed_door)],1)
          prize_door == switched_door
      } else {
          prize_door == guess
          }
  }
  </code></pre>
  
  <p>What changes should I make to get the correct output, which is around <code>0.66</code>?</p>