title: How to loop a formula in a regression model in R
body: <p>Suppose I have a data such like this:</p>
  
  <pre><code>n=100
  df&lt;-data.frame(y=rnorm(n,2,3),
                 x1=rbinom(n,1,0.3),
                 x2=rbinom(n,10, 0.5), 
                 x3=rnorm(n, 50, 20),
                 x4=rnorm(n, 3, 2))  
  </code></pre>
  
  <p>and I have a basic model <code>y=x1+x2</code>:</p>
  
  <pre><code>mod0&lt;-as.formula(y~x1+x2)
  lm0&lt;-lm(mod0, data=df)
  </code></pre>
  
  <p>what I want is to update the mod0 with an interaction term between x1 and each of x3 and x4 such that <code>mod1&lt;-y~x1+x2+x1*x3</code> and <code>mod2&lt;-y~x1+x2+x1*x4</code>. Since I have a bunch of variables need to loop through, I am wondering what it may be a best way for that.</p>