Roll up a list
of arbitrary depth with data.frame
's at the leaves row-wise.
fasten(
list,
into = NULL,
depth = 0
)
A tibble::tibble
or reduced list
A list
with data.frame
's at the leaves.
A character
vector of resulting column names. Defaults to NULL
.
Depth to bind the list to. Defaults to 0.
Alex Zajichek
Use empty strings ""
in the into
argument to omit column creation when rows are binded. Use positive integers for the depth
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. The leaves of the input list
should be at the same depth.
#Make a divided data frame
list <-
heart_disease %>%
divide(
Sex,
HeartDisease,
ChestPain
)
#Bind without creating names
list %>%
fasten
#Bind with names
list %>%
fasten(
into = c("Sex", "HeartDisease", "ChestPain")
)
#Only retain "Sex"
list %>%
fasten(
into = "Sex"
)
#Only retain "HeartDisease"
list %>%
fasten(
into = c("", "HeartDisease")
)
#Bind up to Sex
list %>%
fasten(
into = c("HeartDisease", "ChestPain"),
depth = 1
)
#Same thing, but start at the leaves
list %>%
fasten(
into = c("HeartDisease", "ChestPain"),
depth = -2
)
#Too large of depth returns original list
list %>%
fasten(
depth = 100
)
#Too small of depth goes to 0
list %>%
fasten(
depth = -100
)
Run the code above in your browser using DataLab