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 |
f |
A |
left |
A vector of quoted/unquoted columns, positions, and/or |
right |
A vector of quoted/unquoted columns, positions, and/or |
each_left |
Should each |
each_right |
Should each |
... |
Additional arguments to be passed to |
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"
)