Open In App
Related Articles

Compute the Correlation Coefficient Value between Two Vectors in R Programming – cor() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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 used
Example 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")) 

                    
Output:
[1] 0.9724702
Example 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")) 

                    
Output:
[1] 1
Example 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")) 

                    
Output:
[1] 1


Last Updated : 10 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads