Learn R Programming

corrr (version 0.4.4)

colpair_map: 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)

Value

A correlation data frame (cor_df).

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

Examples

Run this code
## 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)

Run the code above in your browser using DataLab