Skip to content

Instantly share code, notes, and snippets.

View zachary-waller's full-sized avatar

zachary-waller

View GitHub Profile
@zachary-waller
zachary-waller / recursive_split
Last active November 1, 2020 01:36
Recursive Split: Split a dataframe into a nested list and reassemble back into a dataframe
library(purrr)
library(rrapply)
# Split a data frame into a nested list using a different column for each level.
# This uses rrapply::rrapply() to avoid having to do any nested loops (map, lapply,
# for loop, whatever).
# Nested lists can be useful for avoiding searching through your data: the data
# has already been indexed in the list. This can be pretty handy for saving time
# if you need to do lots of filtering stuff.