stratiply {cheese}R Documentation

Stratify a data frame and apply a function

Description

Split a data.frame by any number of columns and apply a function to subset.

Usage

stratiply(
    data,
    f,
    by,
    ...
)

Arguments

data

A data.frame.

f

A function that takes a data.frame as an argument.

by

A vector of quoted/unquoted columns, positions, and/or tidyselect::select_helpers

...

Additional arguments passed to f.

Value

A list

Author(s)

Alex Zajichek

Examples

#Unquoted selection
heart_disease %>%
    stratiply(
        head,
        Sex
    )

#Select helper
heart_disease %>%
    stratiply(
        f = head,
        by = starts_with("S")
    )
    
#Use additional arguments for the function
heart_disease %>%
  stratiply(
        f = glm,
        by = Sex,
        formula = HeartDisease ~ .,
        family = "binomial"
  )

#Use mixed selections to split by desired columns
heart_disease %>%
  stratiply(
        f = glm,
        by = c(Sex, where(is.logical)),
        formula = HeartDisease ~ Age,
        family = "binomial"
  ) 
  

[Package cheese version 0.1.2 Index]