Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split a dataframe into a list of dataframes, but how to re-merge?

Tags:

split

r

I have a big ol' data frame with two ID columns for courses and users, and I needed to split it into one dataframe per course to do some further analysis/subsetting. After eliminating quite a few rows from each of the individual course dataframes, I'll need to stick them back together.

I split it up using, you guessed it, split, and that worked exactly as I needed it to. However, unsplitting was harder than I thought. The R documentation says that "unsplit reverses the effect of split," but my reading on the web so far is suggesting that that is not the case when the elements of the split-out list are themselves dataframes.

What can I do to rejoin my modified dfs?

like image 623
Claire Sannier Avatar asked Nov 30 '22 05:11

Claire Sannier


1 Answers

This is a place for do.call. Simply calling df <- rbind(split.df) will result in a weird and useless list object, but do.call("rbind", split.df) should give you the result you're looking for.

like image 175
Claire Sannier Avatar answered Dec 04 '22 16:12

Claire Sannier