This is solution of given Monty Hall problem.

set.seed(2345)
monty <- function(switch=F) {
  doors = sample(c('car', 'goat', 'goat'), 3)
  pick = sample(1:3, 1)
  
  if (switch) {
    doors[pick] != 'car'
  } else {
    doors[pick] == 'car'
  }
}
no_switch = sapply(1:10000, FUN=function(i) monty())
switch = sapply(1:10000, FUN=function(i) monty(switch=T))
c(mean(no_switch), mean(switch))
## [1] 0.3297 0.6775

Result of problem(No switch):

mean(no_switch)
## [1] 0.3297

Result of problem(Switch):

mean(switch)
## [1] 0.6775