I’m trying to replicate the Monty hall game and when I run this function even though I assign the 3 values to results car, host and player, when the player samples the same as the car I get 4 values returned to results. I don’t understand this behavior.
switch <- FALSE
start_game <- function(switch) {
results <- NULL
doors <- c(1, 2, 3)
car <- sample(doors, size = 1, replace = TRUE)
player <- sample(doors, size = 1, replace = FALSE)
host <- doors[-c(player, car)]
results <- c(car, player, host)
results
}
start_game(switch)