| divide | R Documentation |
Separate a data.frame into a list of any depth by one or more stratification columns whose levels become the names.
divide(
data,
...,
depth = Inf,
remove = TRUE,
drop = TRUE,
sep = "|"
)
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 |
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.
A list
Alex Zajichek
#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
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.