They differ because they're correlations between different things:
cor()
shows the correlation between the input variables,t
andg
.summary(lm(...), correlation=TRUE)
shows the correlation between the estimated parameters, i.e. the slope and the intercept.
If you carefully examine the output of summary()
, you'd notice that it shows the square of the correlation coefficient between t
and g
as Multiple R-squared
:
> summary(lm(g~t))
...
Multiple R-squared: 0.8357, Adjusted R-squared: 0.8122
...
> cor(t,g)**2
[1] 0.8356938