cor2: Correlation function with safe-guards against errors

View source: R/mathematical_functions.R

cor2R Documentation

Correlation function with safe-guards against errors

Description

Correlation function with safe-guards against errors

Usage

cor2(
  x,
  y = NULL,
  use = "everything",
  method = c("pearson", "kendall", "spearman")
)

Arguments

x

a numeric vector, matrix or data frame.

y

NULL (default) or a vector, matrix or data frame with compatible dimensions to x. The default is equivalent to y = x (but more efficient).

use

an optional character string giving a method for computing covariances in the presence of missing values. This must be (an abbreviation of) one of the strings "everything", "all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs".

method

a character string indicating which correlation coefficient (or covariance) is to be computed. One of "pearson" (default), "kendall", or "spearman": can be abbreviated.

Value

The value of cor if successful, otherwise NA.

Note

If x is a two-dimensional object and y is NULL (or missing), then the correlation between the first and second column of x is calculated – unlike cor which calculates all pairwise correlations among all columns of x.

Examples

x <- sample(10)
x <- data.frame(
  val1 = x,
  val2 = x + stats::rnorm(10, 0, 1)
)
cor2(x)


DrylandEcology/rSW2utils documentation built on Dec. 9, 2023, 10:44 p.m.