cor()

cor()

The cor() function will compute the covariance or correlation of x and y if these are vectors. If x and y are matrices then the covariances (or correlations) between the columns of x and the columns of y are computed.

The default method will compute the Pearson correlation coefficient (r), but you may opt to include the 'method' argument to indicate one of "pearson" (default), "kendall", or "spearman". See the link below for additional information:


Example:

# Calculate the correlation between Height and Thumb
cor(Thumb ~ Height, data = Fingers)

Example output:
Output of cor() function


    • Related Articles

    • Arguments (in R Functions)

      Arguments (in R Functions) R function arguments are the inputs provided to a function that determine how it runs and what results it produces. Arguments are placed inside the parentheses of a function call and may represent data, options, or control ...
    • Objects (in Research)

      Objects (in Research) In research, objects—also called cases or research units—are the entities that a study focuses on. They are the “things” about which data are collected and analyzed. Depending on the discipline and research question, objects may ...
    • Cases

      In research, cases—also called objects or research units—are the entities that a study focuses on. They are the “things” about which data are collected and analyzed. Depending on the discipline and research question, cases may be individuals, groups, ...
    • Research Units

      In research, research units—also called objects or cases—are the entities that a study focuses on. They are the “things” about which data are collected and analyzed. Depending on the discipline and research question, research units may be ...
    • correlation coefficient

      Correlation coefficient is a special case of slope in which both the outcome and explanatory variables are transformed into z scores prior to analysis; also known as Pearson's r.