title: Error in formula.default(object, env = baseenv()) when conducting for loop for cointegration test in R
body: <p>I was using for loop in R to conduct adf.test for four series(I expected there would be 16=4X4 adf.test outputs).
  But it returned an error: Error in formula.default(object, env = baseenv()) : invalid formula.Could anyone help me to solve this problem?</p>
  <p>#Here is my data frame which including four series:</p>
  <pre><code>CE_price
   Sonos.Inc GoPro..Inc. Hamilton.Beach.Brands.Holding.Co UNIVERSAL.ELECTRONICS.INC
  1  13.48714    4.110586                         14.94600                  44.99887
  2  13.22786    4.040829                         15.08333                  44.04571
  3  13.83207    4.066529                         15.09615                  45.65071
  4  13.75500    4.022857                         15.13800                  42.13223
  5  13.17276    3.948729                         14.96821                  42.13223
  6  12.18420    3.813100                         14.44910                  42.13223
  </code></pre>
  <p>#Here is my code:</p>
  <pre><code>require(tseries)
  for (i in 1:ncol(CE_price)) {
    for (j in 1:ncol(CE_price)){
    col_i&lt;-colnames(CE_price)[i]
    col_j&lt;-colnames(CE_price)[j]
    comb_i_j&lt;-lm(CE_price[,i],CE_price[,j])
    coin_i_j&lt;-adf.test(comb_i_j$residuals,k=1)
    print(paste(col_i,'&amp;',col_j,'coin_result is',coin_i_j ))
    }}
  </code></pre>
  <p>Return: Error in formula.default(object, env = baseenv()) : invalid formula</p>
  <p>Thanks a lot!</p>