Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

cheese (version 0.1.2)

fasten: Bind a list of data frames back together

Description

Roll up a list of arbitrary depth with data.frame's at the leaves row-wise.

Usage

fasten(
    list,
    into = NULL,
    depth = 0
)

Value

A tibble::tibble or reduced list

Arguments

list

A list with data.frame's at the leaves.

into

A character vector of resulting column names. Defaults to NULL.

depth

Depth to bind the list to. Defaults to 0.

Author

Alex Zajichek

Details

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.

Examples

Run this code
#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