title: Apply lm to subset of data frame defined by a third column of the frame
body: <p>I've got a data frame containing a vector of x values, a vector of y values, and a vector of IDs:</p>
  
  <pre><code>x &lt;- rep(0:3, 3)
  y &lt;- runif(12)
  ID &lt;- c(rep("a", 4), rep("b", 4), rep("c", 4))
  df &lt;- data.frame(ID=ID, x=x, y=y)
  </code></pre>
  
  <p>I'd like to create a separate lm for the subset of x's and y's sharing the same ID.  The following code gets the job done:</p>
  
  <pre><code>a.lm &lt;- lm(x~y, data=subset(df, ID=="a"))
  b.lm &lt;- lm(x~y, data=subset(df, ID=="b"))
  c.lm &lt;- lm(x~y, data=subset(df, ID=="c"))
  </code></pre>
  
  <p>Except that this is very brittle (future data sets might have different IDs) and un-vectorized.  I'd also like to store all the lms in a single data structure.  There must be an elegant way to do this, but I can't find it.  Any help?</p>