#define variables/objects
values <- c(2:10,10,10,10,10)
suit1 <- "clubs"
suit2 <- "hearts"
suit3 <- "spades"
suit4 <- "diamonds"
face <- c("two","three","four","five","six","seven",
"eight","nine","ten","jack","queen","king","ace")
#insert objects into data frames to start constructing the deck
deck1 <- data.frame(value = values,
face_val = face,
suit = suit1)
deck2 <- data.frame(value = values,
face_val = face,
suit = suit2)
deck3 <- data.frame(value = values,
face_val = face,
suit = suit3)
deck4 <- data.frame(value = values,
face_val = face,
suit = suit4)
**sample(deck)
#combine the respective data frames to form one large table, comprising the deck
deck5 <- dplyr::bind_rows(deck1, deck2, deck3, deck4)
View(deck5)
View(deck1)
#concatenate cols 2 and 3 and remove the value col
deck <- deck5 %>%
unite(card, face_val, suit, sep = '-') %>%
select(-value)
#simple deal function
handsize=function(x)
deal <- function(deck, handsize)
hand <- sample_n(deck, size = handsize, replace = TRUE)
return(deal)
deal(deck,5)**
The part from the ** at the bottom is where I run into trouble in figuring out how to return random hand of cards (or deal). I believe I have every card defined properly, now my problem is with calling a random set of cards to be returned. I am not sure how I can fix this or what other functions may be useful to deal with this.
Aucun commentaire:
Enregistrer un commentaire