colpair_map {corrr}R Documentation

Apply a function to all pairs of columns in a data frame

Description

colpair_map() transforms a data frame by applying a function to each pair of its columns. The result is a correlation data frame (see correlate for details).

Usage

colpair_map(.data, .f, ..., .diagonal = NA)

Arguments

.data

A data frame or data frame extension (e.g. a tibble).

.f

A function.

...

Additional arguments passed on to the mapped function.

.diagonal

Value at which to set the diagonal (defaults to NA).

Value

A correlation data frame (cor_df).

Examples

## Using `stats::cov` produces a covariance data frame.
colpair_map(mtcars, cov)

## Function to get the p-value from a t-test:
calc_p_value <- function(vec_a, vec_b) {
  t.test(vec_a, vec_b)$p.value
}

colpair_map(mtcars, calc_p_value)

[Package corrr version 0.4.4 Index]