title: Generating sample data in a function in r without repeat
body: <p>I have the following reproducible code: </p>
  
  <pre><code>x &lt;- as.data.table(c(1:20))
  samplefunction &lt;- function(x) { 
  if(x &lt;= 10 ) { 
  sample(35:45)
  }else if(x &gt; 10) { 
  sample(50:60)
  }
  }
  
  day1 &lt;- x[,sales := sapply(x, samplefunction)]
  day2 &lt;- x[,sales := sapply(x, samplefunction)]
  </code></pre>
  
  <p>Both day1 and day2 populate the sample value for sales. It looks like the value returned from samplefunction is re-used for each iteration. How can I create seperate data frames (day1, day2,...) and re-generate random data for the sales column each time? Set.Seed() is used to re-use the same random generation..I'm looking for the opposite, in a sense. Thank you. </p>