← Back to R Course | Chapter 9: Statistics | Lesson 4 of 7

cor()

In this page:

  1. cor()

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()

markup
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 6, 8, 10)

cat("Correlation:", cor(x, y), "\n")
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.