You need some statistical knowledge to see this. R squared between two vectors is simply the square of their correlation . So you can define your function as:
rsq <- function (x, y) cor(x, y) ^ 2
Sandipan (. ), (- $r.squared).
, y x .
1: y ~ x y - mean(y) ~ x - mean(x)

2: = cov (x, y)/var (x)

3: R.square = cor (x, y) ^ 2

R x y ( ) - . !! R x + a y + b a b. " ". MSE RMSE:
42-:
R , . , .
R ( ) " ". , . , R , R . , .
:
preds <- 1:4/4
actual <- 1:4
R 1. , , - , . , preds actual?
1, 2 .
, , . x y y ~ x . , . , , R .
, R :
preds <- c(1, 2, 3)
actual <- c(2, 2, 4)
rss <- sum((preds - actual) ^ 2)
tss <- sum((actual - mean(actual)) ^ 2)
rsq <- 1 - rss/tss
:
regss <- sum((preds - mean(preds)) ^ 2)
regss / tss
, ( 1, "").
preds <- 1:4 / 4
actual <- 1:4
rss <- sum((preds - actual) ^ 2)
tss <- sum((actual - mean(actual)) ^ 2)
rsq <- 1 - rss/tss
, , 2 . , , . , , R , R .