title: Ancova using variable selected from loop (R)
body: <p>I have 1,000 dependent variables (y) to use in Ancova. Independent variables (x) is the same in all models. </p>
  
  <pre><code>Yvar1, Yvar2, …, Yvar1000, x1, x2
  1       2          5       11  16
  2       3          6       18  23
  </code></pre>
  
  <p>I need an R code that replace <code>example$Y.to.use</code> values for each Yvar.</p>
  
  <p>I tried this: </p>
  
  <pre><code>for (i in 1:1000){ 
  example$Y.to.use&lt;- example$paste("Yvar",i, sep="")
  
  # Error: attempt to apply non-function
  
  paste("fitted.model",i)&lt;-lme(log(Y.to.use+1)  ~ x1*x2, data=example, random=~1| Exp/Person)
  } 
  
  # Error in paste("fitted.model", i, sep = "") &lt;- lme(log(Y.to.use+1)  ~ x1*x2  : target of assignment expands to non-language object
  </code></pre>
  
  <p>I will create a table with coefficients from each fitted model of each Yvar.</p>