title: r dplyr sample_frac using seed in data
body: <p>I have a grouped data frame, in which the grouping variable is <code>SEED</code>. I want to take the groups defined by the values of <code>SEED</code>, set the seed to the value of <code>SEED</code> for each group, and then shuffle the rows of each group using <code>dplyr::sample_frac</code>. However, I cannot replicate my results, which indicates that the seed isn't being set correctly.</p>
  
  <p>To do this in a <code>dplyr</code>-ish way, I wrote the following function:</p>
  
  <pre><code>&gt; library(dplyr)
  &gt; ss_sampleseed &lt;- function(df, seed.){
  &gt;   set.seed(df$seed.)
  &gt;   sample_frac(df, 1)
  &gt; }
  </code></pre>
  
  <p>I then use this function on my data:</p>
  
  <pre><code>&gt; dg &lt;- structure(list(Gene = c("CAMK1", "ARPC4", "CIDEC", "CAMK1", "ARPC4", 
  &gt; "CIDEC"), GENESEED = c(1, 1, 1, 2, 2, 2)), class = c("tbl_df", 
  &gt; "tbl", "data.frame"), row.names = c(NA, -6L), .Names = c("Gene", 
  &gt; "GENESEED"))
  
  &gt; dg2 &lt;- dg %&gt;%
  &gt;   group_by(GENESEED) %&gt;%
  &gt;   ss_sampleseed(GENESEED)
  
  &gt; dg2
  Source: local data frame [6 x 2]
  Groups: GENESEED
  
     Gene GENESEED
  1 ARPC4        1
  2 CIDEC        1
  3 CAMK1        1
  4 CIDEC        2
  5 ARPC4        2
  6 CAMK1        2
  </code></pre>
  
  <p>However, when I repeat the above code, I cannot replicate my results.</p>
  
  <pre><code>&gt; dg2
  Source: local data frame [6 x 2]
  Groups: GENESEED
  
     Gene GENESEED
  1 ARPC4        1
  2 CAMK1        1
  3 CIDEC        1
  4 CAMK1        2
  5 ARPC4        2
  6 CIDEC        2
  </code></pre>