divide {cheese}R Documentation

Divide a data frame into a list

Description

Separate a data.frame into a list of any depth by one or more stratification columns whose levels become the names.

Usage

divide(
    data,
    ...,
    depth = Inf,
    remove = TRUE,
    drop = TRUE,
    sep = "|"
)

Arguments

data

Any data.frame.

...

Selection of columns to split by. See dplyr::select for details.

depth

Depth to split to. Defaults to Inf. See details for more information.

remove

Should the stratfication columns be removed? Defaults to TRUE.

drop

Should unused combinations of stratification variables be dropped? Defaults to TRUE.

sep

String to separate values of each stratification variable by. Defaults to "|". Only used when the number of stratification columns exceeds the desired depth.

Details

For the depth, use positive integers to move from the root and negative integers to move from the leaves. The maximum (minimum) depth will be used for integers larger (smaller) than such.

Value

A list

Author(s)

Alex Zajichek

Examples

#Unquoted selection
heart_disease %>%
    divide(
        Sex
    )

#Using select helpers
heart_disease %>%
    divide(
        matches("^S")
    )

#Reduced depth
heart_disease %>%
    divide(
        Sex,
        HeartDisease,
        depth = 1
    )
    
#Keep columns in result; change delimiter in names
heart_disease %>%
    divide(
        Sex,
        HeartDisease,
        depth = 1,
        remove = FALSE,
        sep = ","
    )

#Move inward from maximum depth
heart_disease %>%
    divide(
        Sex,
        HeartDisease,
        ChestPain,
        depth = -1
    )

#No depth returns original data (and warning)
heart_disease %>%
    divide(
        Sex,
        depth = 0
    )
heart_disease %>%
    divide(
        Sex,
        HeartDisease,
        depth = -5
    )

#Larger than maximum depth returns maximum depth (default)
heart_disease %>%
    divide(
        Sex,
        depth = 100
    )


[Package cheese version 0.1.2 Index]