corrr (version 0.4.0)

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)

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.

Value

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

Examples

Run this code
# NOT RUN {
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 DataCamp Workspace