Hey everyone! I am new to rstudio and would like some help figuring out how to solve the correlation coeffecient for 2 variables given (weight and exercise_minutes). I have attached what I have done so far below.
The correlation coeffecient i am getting is incorect it should be 0.3763526 but i am getting 464394961 (a much higher number than expected) not sure why...any help is greatly appreciated. Also, the formula for determine the coeffecient correlation is written as a comment.
#Section 2 - 2.4
df$new_variable1 <- (df$weight - mean(df$weight))
#Section 2 - 2.5
df$new_variable2 <- (df$excercise_minutes - mean(excercise_minutes))
#Section 2 - 2.6
df$product_2_variables <- df$new_variable1 * df$new_variable2
#Section 2 - 2.7
r = (xi}-{x})({yi}-{y}))/(N-1)(SxSy)
(sum(product_2_variables))/(20-1)*sd(weight)*sd(excercise_minutes)