cor() function in R Language is used to measure the correlation coefficient value between two vectors.
Syntax: cor(x, y, method) Parameters: x, y: Data vectors method: Type of method to be usedExample 1:
# Data vectors
x <- c(1, 3, 5, 10)
y <- c(2, 4, 6, 20)
# Print covariance using Pearson method
print(cor(x, y, method = "pearson"))
[1] 0.9724702Example 2:
# Data vectors
x <- c(1, 3, 5, 10)
y <- c(2, 4, 6, 20)
# Print covariance using Pearson method
print(cor(x, y, method = "kendall"))
[1] 1Example 3:
# Data vectors
x <- c(1, 3, 5, 10)
y <- c(2, 4, 6, 20)
# Print covariance using Pearson method
print(cor(x, y, method = "spearman"))
[1] 1