Function to calculate R2 (R-squared) in R
<p>I have a dataframe with observed and modelled data, and I would like to calculate the R2 value.  I expected there to be a function I could call for this, but can't locate one.  I know I can write my own and apply it, but am I missing something obvious?  I want something like</p>

<pre><code>obs &lt;- 1:5
mod &lt;- c(0.8,2.4,2,3,4.8)
df &lt;- data.frame(obs, mod)

R2 &lt;- rsq(df)
# 0.85
</code></pre>