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