cor()
In this page:
cor()
cor(x, y) computes the Pearson correlation coefficient between two numeric vectors, a value between -1 and 1 describing how strongly they move together linearly. A value near 1 means strong positive correlation, near -1 means strong negative correlation, and near 0 means little linear relationship. It's a foundational tool for exploring relationships between variables.
Note: A correlation near 0 does not mean there is no relationship -- it only means there is no linear relationship.
Example: cor()
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 6, 8, 10)
cat("Correlation:", cor(x, y), "\n")
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: