how to get r^2 in r code example Example: how to get the r2 value in r rsq <- function (x, y) cor(x, y) ^ 2