title: Fitting a glm using variable as a column name in R
body: <p>I am trying to fit a <code>glm()</code> in R using a variable instead of column names but it is not working. This can help me generate glms automatically. When I fit the <code>glm</code> using the column names, the program runs fine, when I exchange the column names with the variable that contains the column names, the program gives and error.</p>
  
  <p>Here's what my command looks like:</p>
  
  <pre><code>##The data
  mydata &lt;- structure(list(var1 = c(10L, 100L, 50L, 40L, 20L, 50L, 60L, 55L, 
  45L), var2 = c(1.5, 1.2, 1, 1.4, 1.2, 1.4, 1.3, 1.4, 1.3), var3 = c(5L, 
  3L, 4L, 1L, 5L, 2L, 7L, 5L, 4L), group = structure(c(1L, 1L, 
  2L, 2L, 1L, 1L, 2L, 1L, 1L), .Label = c("A", "B"), class = "factor")), .Names = c("var1", 
  "var2", "var3", "group"), class = "data.frame", row.names = c(NA, 
  -9L))
  ## My variable
  x &lt;- c("var1+var2")
  ##Fitting the model
  myglm &lt;- glm(formula = group ~ var1+var2 , family = "binomial", data = mydata) ## works fine
  
  
  myglm2 &lt;- glm(formula = group ~ x , family = "binomial", data = mydata)
  Error in model.frame.default(formula = group ~ x, data = mydata, drop.unused.levels = TRUE) : 
    variable lengths differ (found for 'x')
  </code></pre>
  
  <p>I tried to use <code>paste(x)</code> and <code>cat(x)</code> functions, but it did not work.
  Is it possible to do this in R? I need to use this because I am making around 1000 <code>glm</code> in a for loop.</p>