title: How to call a function with dlply argument?
body: <p>I wish to write a function using <code>dlply</code> to fit a linear regression stratified by </p>
  
  <pre><code>"cat1 by arg1"
  </code></pre>
  
  <p>So my function looks like this</p>
  
  <pre><code>fun1 &lt;- function(arg1) {
       m1 &lt;- data.frame(...) 
       mod.var &lt;- ...
       mod.form &lt;- formula(paste("y ~", paste(mod.var, collapse = " + ")))
       list_of_models &lt;- dlply(m1, .(cat1,arg1), function(X) lm(mod.form, data = X, 
            na.action=na.omit), .parallel=FALSE) 
  }
  </code></pre>
  
  <p>How to write a function so that when I call the function <code>fun1("cat2")</code> the function will execute</p>
  
  <pre><code>list_of_models &lt;- dlply(m1, .(cat1,cat2), function(X) lm(mod.form, data = X,
      na.action = na.omit), .parallel=FALSE)
  </code></pre>
  
  <p>and call the function <code>fun1("cat3")</code>, the function will execute  </p>
  
  <pre><code>list_of_models &lt;- dlply(m1,.(cat1,cat3), function(X) lm(mod.form, data = X,
      na.action=na.omit), .parallel=FALSE)
  </code></pre>
  
  <p>where <code>cat1</code>, <code>cat2</code> and <code>cat3</code> are the names of categorical variables.</p>
  
  <p>Thank you for your help. </p>
  
  <p>Edit: As the function stands at the moment, it does not work properly because <code>".(cat1,arg1)"</code> is not "recognizable" in <code>dlply</code>. Some modifications are needed, but how?</p>