Learn R Programming

tidyna (version 0.4.0)

correlation-functions: NA-aware Correlation Function

Description

Drop-in replacement for cor() that defaults to use = "pairwise.complete.obs".

Usage

cor(
  x,
  y = NULL,
  use = "pairwise.complete.obs",
  method = c("pearson", "kendall", "spearman"),
  ...
)

Value

A correlation matrix or single correlation coefficient.

Arguments

x

A numeric vector, matrix, or data frame.

y

Optional. A numeric vector, matrix, or data frame.

use

Method for handling missing values. Default "pairwise.complete.obs".

method

Correlation method: "pearson", "kendall", or "spearman".

...

Additional arguments passed to stats::cor().

Examples

Run this code
x <- c(1, 2, NA, 4)
y <- c(2, 4, 6, 8)
cor(x, y)

Run the code above in your browser using DataLab