Running several linear regressions from a single dataframe in R
<p>I have a dataset of export trade data for a single country with 21 columns. The first column indicates the years (1962-2014) while the other 20 are trading partners. I am trying to run linear regressions for the years column and each other column. I have tried the method recommended here: <a href="https://stackoverflow.com/questions/18947563/running-multiple-simple-linear-regressions-from-dataframe-in-r">Running multiple, simple linear regressions from dataframe in R</a> that entails using</p>

<pre><code>combn(names(DF), 2, function(x){lm(DF[, x])}, simplify = FALSE)
</code></pre>

<p>However this only yields the intercept for each pair which is less important to me than the slope of the regressions.</p>

<p>Additionally I have tried to use my dataset as a time series, however when I try to run </p>

<pre><code>lm(dimnames~., brazilts, na.action=na.exclude)
</code></pre>

<p>(where <code>brazilts</code> is my dataset as a time series from "1962" to "2014") it returns:</p>

<pre><code>Error in model.frame.default(formula = dimnames ~ ., data = brazilts,  : 
  object is not a matrix.
</code></pre>

<p>I therefore tried the same method with a matrix but then it returned the error:</p>

<pre><code>Error in model.frame.default(formula = . ~ YEAR, data = brazilmatrix,  : 
  'data' must be a data.frame, not a matrix or an array
</code></pre>

<p>(where <code>brazilmatrix</code> is my dataset as a <code>data.matrix</code> which includes a column for years).</p>

<p>Really I am not even proficient in R and at this point. The ultimate goal is to create a loop that I can use to get take regressions for a significantly larger dataset of gross exports by country-pair per year for 28 countries. Perhaps I am attacking this in entirely the wrong way, so any help or criticism is welcome. Bare in mind that the years (1962-2014) are in effect my explanatory variable and the value of gross export is my dependent variable, which may be throwing off my syntax in the above examples. Thanks in advance!</p>