dish {cheese}R Documentation

Evaluate a two-argument function with combinations of columns

Description

Split up columns into groups and apply a function to combinations of those columns with control over whether each group is entered as a single data.frame or individual vector's.

Usage

dish(
    data,
    f,
    left,
    right,
    each_left = TRUE,
    each_right = TRUE,
    ...
)

Arguments

data

A data.frame.

f

A function that takes a vector and/or data.frame in the first two arguments.

left

A vector of quoted/unquoted columns, positions, and/or tidyselect::select_helpers to be evaluated in the first argument of f.

right

A vector of quoted/unquoted columns, positions, and/or tidyselect::select_helpers to be evaluated in the second argument of f.

each_left

Should each left variable be indivdually evaluated in f? Defaults to TRUE. If FALSE, left columns are entered into f as a single data.frame.

each_right

Should each right variable be individually evaluated in f? Defaults to TRUE. If FALSE, right columns are entered into f as a single data.frame.

...

Additional arguments to be passed to f.

Value

A list

Author(s)

Alex Zajichek

Examples

#All variables on both sides
heart_disease %>%
    dplyr::select(
        where(is.numeric)
    ) %>%
    dish(
        f = cor
    )

#Simple regression of each numeric variable on each other variable
heart_disease %>%
    dish(
        f =
            function(y, x) {
                mod <- lm(y ~ x)
                tibble::tibble(
                    Parameter = names(mod$coef),
                    Estimate = mod$coef
                )
            },
        left = where(is.numeric)
    ) %>%
    
    #Bind rows together
    fasten(
        into = c("Outcome", "Predictor")
    )

#Multiple regression of each numeric variable on all others simultaneously
heart_disease %>%
    dish(
        f =
            function(y, x) {
                mod <- lm(y ~ ., data = x)
                tibble::tibble(
                    Parameter = names(mod$coef),
                    Estimate = mod$coef
                )
            },
        left = where(is.numeric),
        each_right = FALSE
    ) %>%
    
    #Bind rows together
    fasten(
        into = "Outcome"
    )


[Package cheese version 0.1.2 Index]