I have a dataframe made up of 400’000 rows and about 50 columns. As this dataframe is so large, it is too computationally taxing to work with.
I would like to split this dataframe up into smaller ones, after which I will run the functions I would like to run, and then reassemble the dataframe at the end.
There is no grouping variable that I would like to use to split up this dataframe. I would just like to split it up by number of rows. For example, I would like to split this 400’000-row table into 400 1’000-row dataframes.
How might I do this?
Make your own grouping variable.
You should also consider the
ddplyfunction from theplyrpackage, or thegroup_by()function fromdplyr.edited for brevity, after Hadley’s comments.
If you don’t know how many rows are in the data frame, or if the data frame might be an unequal length of your desired chunk size, you can do
You could also use
For future readers, methods based on the
dplyranddata.tablepackages will probably be (much) faster for doing group-wise operations on data frames, e.g. something likeThere are also many answers here