corrr (version 0.4.4)

focus_if: Conditionally focus correlation data frame

Description

Apply a predicate function to each column of correlations. Columns that evaluate to TRUE will be included in a call to focus.

Usage

focus_if(x, .predicate, ..., mirror = FALSE)

Value

A tibble or, if mirror = TRUE, a correlation data frame.

Arguments

x

Correlation data frame or object to be coerced to one via as_cordf.

.predicate

A predicate function to be applied to the columns. The columns for which .predicate returns TRUE will be included as variables in focus.

...

Additional arguments to pass to the predicate function if not anonymous.

mirror

Boolean. Whether to mirror the selected columns in the rows or not.

Examples

Run this code
library(dplyr)
any_greater_than <- function(x, val) {
  mean(abs(x), na.rm = TRUE) > val
}

x <- correlate(mtcars)

x %>% focus_if(any_greater_than, .6)
x %>% focus_if(any_greater_than, .6, mirror = TRUE) %>% network_plot()

Run the code above in your browser using DataLab