I have the following Python function,
import random
import math
deck = [2,3,4,5,6,7,8,9,10,10,10,10,11]
def draw_card(deck):
card = deck.pop(random.sample(range(len(deck)), 1)[0])
return(card)
print(deck,'\n')
my_draw = draw_card(deck)
print(my_draw, '\n')
print(deck, '\n')
The output is below,
[2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11]
3
[2, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11]
I need to convert this to R but I understand there is no equivalent Python list.pop function in R. I am not worried about random pick as I can do a rep in R and am able to emulate the drawing of card in R by,
DrawCard <- function(card){
card <- tail(deck,1)
return(card)
}
Also I am able remove the same drawn card by head(deck, -1) but I do not know how to feed the 2 in 1 function like in Python that will return both the card value and also the shorter length deck.
Please help.
Thanks, Lobbie
list.popwould be to subset twice. See?samplefor shuffling.