title: How to turn model into function in R
body: <p>Let's say, I've got myself a linear model with <code>lm</code>. Just a trivial one:</p>
  
  <pre><code>x = 1:10
  y = 1:10
  lm1 = lm(y ~ x)
  </code></pre>
  
  <p>Now I want to turn it into a function, which in this particular example would behave simply like <code>function(x) {x}</code>. How do I do that? </p>
  
  <p>Well, one way would be to use predict: </p>
  
  <pre><code>f = function(x) { predict(lm1, newdata = data.frame( x ) ) }
  </code></pre>
  
  <p>But this looks needlessly cumbersome. Is there a better way?</p>