title: How to run a function dynamically from 1 to n times in R?
body: <p>I have a data set named <code>master</code> that contains survey data, structured like:</p>
  
  <pre><code>Pid state msr_01 foot_01 msr_02 foot_02 … msr_n foot_n
  </code></pre>
  
  <p>I want to have n data sets fetched from <code>master</code>, like:</p>
  
  <blockquote>
    <p>out_01 contains: Pid
    state msr_01 foot_01 msrid  <br/> 
    out_02 contains: Pid state msr_02 foot_02
    msrid  <br/> 
    out_n contains: Pid state msr_n foot_n msrid</p>
  </blockquote>
  
  <p>The function below does this: </p>
  
  <pre class="lang-r prettyprint-override"><code>gen_wkds &lt;- function (df, pno, st, col1, col2,newcol, newvalue){
    colnames &lt;- c(pno, st, col1, col2)
    new_df &lt;- df[, c(colnames)]
    colnames( new_df)[3] &lt;- "Rate"
    colnames( new_df)[4] &lt;- "Footnote"
    new_df[[newcol]] &lt;- newvalue
    return(new_df)
  }
  </code></pre>
  
  <p>How can I run this function dynamically from 1 to n times and generate n data sets? </p>