title: Trying to generate a data frame from values in another data frame using dplyr and purrr
body: <p>I'm trying to create a data frame that is generated based on the content of another data frame. In the example below I use the <code>n_seqs</code> column of a tibble to specify the mean for the <code>rnorm</code> function and then I generate <code>my_tibble</code>. The first column of <code>my_tibble</code> should contain the value from the <code>group</code> column and the subsequent columns should contain the 10 random values from running <code>rnorm</code>. As the reproducible example below shows, I'm able to get this to work through a fairly hacky approach.</p>
  
  <p>I don't understand...</p>
  
  <ul>
  <li>Why I have to do <code>pull</code> and can't specify <code>n_seqs</code> in the <code>map</code> function. Also</li>
  <li>Whether there's a way to name the individual entries in the list so that I can use <code>map_dfr</code> or <code>bind_rows</code></li>
  <li>What is the best <code>dplyr</code>/<code>purrr</code> approach do get the desired result?</li>
  </ul>
  
  
  
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  my_tibble &lt;- tibble(group=c("A", "B", "C"), n_seqs=c(5,7,10)) %&gt;%
                                  pull(n_seqs) %&gt;%
                                  map(function(x){ z &lt;- rnorm(x, n=10); names(z) &lt;- letters[1:10]; return(z) })
  my_tibble
  #&gt; [[1]]
  #&gt;        a        b        c        d        e        f        g        h 
  #&gt; 6.518214 4.305639 6.106827 5.118304 4.255043 5.678025 4.345129 4.914239 
  #&gt;        i        j 
  #&gt; 6.727135 6.030590 
  #&gt; 
  #&gt; [[2]]
  #&gt;        a        b        c        d        e        f        g        h 
  #&gt; 7.969410 7.558780 8.265322 8.004338 6.862732 5.517313 8.061683 4.062385 
  #&gt;        i        j 
  #&gt; 6.693430 7.858993 
  #&gt; 
  #&gt; [[3]]
  #&gt;         a         b         c         d         e         f         g 
  #&gt;  9.066362  9.921300 10.724671  8.643903  9.783747  9.102569 10.489579 
  #&gt;         h         i         j 
  #&gt;  9.156070  9.863332 11.148255
  
  
  #error
  my_tibble %&gt;% bind_rows(.)
  #&gt; Error in bind_rows_(x, .id): Argument 1 must have names
  
  
  # deprecated warning, but desired output
  my_tibble %&gt;% rbind_list %&gt;% mutate(sample=c("A", "B", "C")) %&gt;% select(sample, everything())
  #&gt; Warning: 'rbind_list' is deprecated.
  #&gt; Use 'bind_rows()' instead.
  #&gt; See help("Deprecated")
  #&gt; # A tibble: 3 x 11
  #&gt;   sample     a     b     c     d     e     f     g     h     i     j
  #&gt;   &lt;chr&gt;  &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
  #&gt; 1 A       6.52  4.31  6.11  5.12  4.26  5.68  4.35  4.91  6.73  6.03
  #&gt; 2 B       7.97  7.56  8.27  8.00  6.86  5.52  8.06  4.06  6.69  7.86
  #&gt; 3 C       9.07  9.92 10.7   8.64  9.78  9.10 10.5   9.16  9.86 11.1
  
  
  #desired output
  my_tibble %&gt;% do.call(rbind, .) %&gt;% as.tibble() %&gt;% mutate(sample=c("A", "B", "C")) %&gt;% select(sample, everything())
  #&gt; # A tibble: 3 x 11
  #&gt;   sample     a     b     c     d     e     f     g     h     i     j
  #&gt;   &lt;chr&gt;  &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
  #&gt; 1 A       6.52  4.31  6.11  5.12  4.26  5.68  4.35  4.91  6.73  6.03
  #&gt; 2 B       7.97  7.56  8.27  8.00  6.86  5.52  8.06  4.06  6.69  7.86
  #&gt; 3 C       9.07  9.92 10.7   8.64  9.78  9.10 10.5   9.16  9.86 11.1
  </code></pre>
  
  <p>Created on 2018-06-12 by the <a href="http://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.2.0).</p>