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

View source: R/colpair.R

colpair_mapR 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)

corrr documentation built on Aug. 17, 2022, 1:05 a.m.