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 |
... |
Selection of columns to split by. See |
depth |
Depth to split to. Defaults to |
remove |
Should the stratfication columns be removed? Defaults to |
drop |
Should unused combinations of stratification variables be dropped? Defaults to |
sep |
String to separate values of each stratification variable by. Defaults to |
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
)