Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Calculate cosine of a value in R Programming - cos() Function
Next article icon

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

Last Updated : 10 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
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  


Next Article
Calculate cosine of a value in R Programming - cos() Function

N

nidhi_biet
Improve
Article Tags :
  • R Language
  • R Math-Function
  • R Vector-Function

Similar Reads

  • Compute the Covariance between Two Vectors in R Programming - cov() Function
    cov() function in R Language is used to measure the covariance between two vectors. Syntax: cov(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(cov(x,
    1 min read
  • Compute the beta value of Non-Negative Numeric Vectors in R Programming - beta() Function
    beta() function in R Language is used to return the beta value computed using the beta function. The beta function is also known as Euler's integral of the first kind. Syntax: beta(a, b) Parameters: a, b: non-negative numeric vectors Example 1: # R program to illustrate # beta function # Calling the
    1 min read
  • How to Extract Correlation Coefficient Value from Correlation Test in R
    In R Language you can compute the correlation between two variables using functions like cor() or cor.test(). The cor() the function gives the correlation coefficient directly, while the cor.test() function provides a more comprehensive output, including the correlation coefficient, p-value, confide
    3 min read
  • Calculate cosine of a value in R Programming - cos() Function
    cos() function in R Language is used to calculate the cosine value of the numeric value passed to it as argument. Syntax: cos(x) Parameter: x: Numeric value Example 1: # R code to calculate cosine of a value # Assigning values to variables x1 <- 90 x2 <- 30 # Using cos() Function cos(x1) cos(x
    1 min read
  • Calculate Rank of the Values of a Vector in R Programming - rank() Function
    rank() function in R Language is used to return the sample ranks of the values of a vector. Equal values and missing values are handled in multiple ways. Syntax: rank(x, na.last) Parameters: x: numeric, complex, character, and logical vector na.last: Boolean Value to remove NAs Example 1: # R progra
    1 min read
  • Calculate the Cumulative Minima of a Vector in R Programming - cummin() Function
    cummin() function in R Language is used to calculate the cumulative minima of the values of vector passed as arguments. Syntax: cummin(x) Parameters: x: numeric object Example 1: # R program to cumulative minima # Calling cummin() function cummin(2:6) cummin(-2:-6) cummin(1.8:4.2) Output: [1] 2 2 2
    1 min read
  • How to Find P-Value for Correlation Coefficient in R
    Correlation is a statistical technique used to determine the strength and direction of the linear relationship between two variables. The correlation coefficient (denoted as r) quantifies this relationship, but understanding whether this correlation is statistically significant is just as important.
    3 min read
  • Add Correlation Coefficients with P-values to a Scatter Plot in R
    In this article, we will discuss how to add correlation coefficients with P-value to a scatter plot in the R Programming Language. To add correlation coefficient with P-value to a scatter plot, we use the stat_cor() function of the ggpubr package in the R Language. The ggpubr package provides some e
    2 min read
  • Compute the cosine value which is multiples of pi in R Programming - cospi() Function
    cospi() function in R Language is used to compute the cosine value of x which is the multiples of pi. Syntax: cospi(x) Parameters: x: Numeric value, array or vector Example 1: # R program to illustrate # cospi function # Calling the cospi() function cospi(0) cospi(1) Output: [1] 1 [1] -1 Example 2:
    1 min read
  • Calculate arc cosine of a value in R programming - acos() function
    The acos() is an inbuilt function in R Programming which is used to calculate arc cosine of the specified radian value and output is also in radians. Syntax: acos(radian) Return: Returns the arc cosine value of radian. Example 1: # Using acos() method gfg <- acos(pi/4) print(gfg) Output: [1] 0.78
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences