Reputation: 507
I am working on a poker deck prability simulation. I would like to get the probability that player 1 is dealt a hand consisting of a single suit only. I got the code below, however, I get the following error:
> checkDeck1()
Error in unique(deck[1:4]) : argument "deck" is missing, with no default
Code:
pokerdeck <- rep(LETTERS[1:4],13)
deck <- sample(x=pokerdeck, size=13) #Deck of player 1!
checkDeck1 <- function(deck) {
uniquedeck <- unique(deck[1:13])
## if it is only a single suit
if (length(uniquedeck)==1) {
rv <- TRUE
} else {
rv <- FALSE
}
return (rv)
}
checkDeck1()
Upvotes: 1
Views: 786
Reputation: 4661
You want to call
checkDeck1(deck)
In the code of your function checkDeck1, the scope of the variable deck is local - the fact that you name this variable like a global variable locally overwrites it.
Upvotes: 2