I’ve been encountering lists of data frames both at work and at play. Most of the time, I need only bind them together
purrr::map_df(). But recently I’ve needed to join them by a shared key. This operation is
more complex. In fact, I admitted defeat earlier this year when I allowed
rcicero::get_official() to return a list of data frames rather than
a single, tidy table. Forgiveable at the time, but now I know better.
For a quick demonstration, let’s get our list of data frames:
Now we have a list of data frames that share one key column: “A”. I needed some programmatic way to join each data frame to the next,
and while cycling through abstractions, I recalled the reduce function from Python, and I was ready to bet my life R had something similar. And we do:
for basers, there’s
Reduce(), but for civilized, tidyverse folk there’s
Here’s how to create and merge
df_list together with base R and
Hideous, right?! Behold the glory of the tidyverse:
There’s just no comparison. I need to go back and implement this little trick in rcicero pronto.
That is quite a bit of power with just a dash of tidyverse piping.