title: Creating a list of all possibilities
body: <p>I'm trying to create a dataframe containing all the possible combinations of A and B in a string with six characters. For example, (A, A, B, B, A, A) and (A, A, B, A, A, A) etc... First, I assigned 6 to the variable n, and then I created a simple vector with A and B.</p>
  <pre><code>n &lt;- 6
  choice &lt;- c(&quot;A&quot;, &quot;B&quot;)
  </code></pre>
  <p>Then I used sample() to choose a random letter, with replacement, six times. The sample() part of my code is functioning the way I want it to, but I'm struggling to make a list of all possibilities. Here is what I have so far:</p>
  <pre><code>list &lt;- rep(list(sample(choices, n, replace = TRUE)))
  </code></pre>
  <p>But this only gives me one string. I want it to be however many strings are required to cover every possibility. I thought maybe expand.grid() would help:</p>
  <pre><code>df &lt;- &lt;- expand.grid(as.character(list))
  </code></pre>
  <p>But the problem here is that all strings are identical, so obviously I'm not getting every possibility. Will someone please help me create a list with all possible combinations of A and B, with replacement?</p>
  <p>I'm not supposed to use the permutations() function, unfortunately.</p>