title: Creating A Deck Of Cards In R Without Using While And Double For Loop
body: <p>I am creating a blackjack simulator in R.  The code below succeeds in creating the deck(s) of cards that I want.  (For those that play, I will deal with the value of an Ace later).</p>
  
  <p>My question is, is there a better way to create the deck that doesn't involve a while loop plus a double for loop?  I have more of an issue with the double for loop.  The while loop is likely unavoidable since the number of decks created is variable.</p>
  
  <p>I also initialize an empty data frame which I know isn't the best practice, however, the data set is so small in this case that it won't effect performance.</p>
  
  <p>And lastly, is there an equivalent of i++ in R?  I have been programming in java as well and have gotten used to it.</p>
  
  <p>Thanks.</p>
  
  <pre><code>createDeck &lt;- function(totalNumOfDecks = 2)
  {
    suits &lt;- c("Diamonds", "Clubs", "Hearts", "Spades")
    cards &lt;- c("Ace", "Deuce", "Three", "Four","Five", 
               "Six", "Seven", "Eight", "Nine", "Ten", 
               "Jack", "Queen", "King")
    values &lt;- c(0,2,3,4,5,
                6,7,8,9,10,
                10,10,10)
  
    deck &lt;- data.frame(Suit=character(0), Card=character(0), Value=numeric(0))
  
    numOfDecks = 1
  
    while (numOfDecks &lt;= totalNumOfDecks){
      for (i in suits){
        for (j in cards){
          deck &lt;- rbind.data.frame(deck, cbind.data.frame(j, i, values[match(j, cards)]))
        }
      }
      numOfDecks = numOfDecks + 1
    }
  
    print(deck)
  }
  </code></pre>