title: How to apply a function that contains multiple regression on 2 by 2 variables in df by category in R?
body: <p>My df is somthing like this: </p>
  
  <pre><code>ind1 &lt;- rnorm(99)
  ind2 &lt;- rnorm(99)
  ind3 &lt;- rnorm(99)
  ind4 &lt;- rnorm(99)
  ind5 &lt;- rnorm(99)
  dep &lt;- rnorm(99, mean=ind1)
  group &lt;- rep(c("A", "B", "C"), each=33)
  df &lt;- data.frame(dep, group, ind1, ind2, ind3, ind4, ind5)
  </code></pre>
  
  <p>This is a function that combines different types of regression equations. </p>
  
  <pre><code>functions &lt;- function(x, y) {
    eq1 &lt;- lm(dep ~ x + y)
    eq2 &lt;- lm(dep ~ I(x*y))
    eq3 &lt;- lm(log(dep) ~ I(log(x+1)^2) + I(log(y+1)^2))
    list &lt;- list(eq1, eq2, eq3)
    names(list) &lt;- paste0("mod", 1:3)
    return(list)
  }
  </code></pre>
  
  <p>Then I applied this function to ind1 and ind2 variables by group as below. </p>
  
  <pre><code>out &lt;- lapply(split(df, df$group), function(x) functions(x$ind1, x$ind2))
  lapply(out, summary)
  </code></pre>
  
  <p>But there is a error saying that variable lengths differ (found for 'x')? So how I can fix this error?</p>
  
  <p>Thanks in advance!</p>