r - Is there a function to split a large dataframe into n smaller dataframes of equal size (by row) and have an n+1 dataframe of smaller size? -
the title pretty states it. have data frame has 7+million rows, far big me analyze without machine crashing. want split 100 smaller dataframes of 70,000 rows, , have 101th dataframe have remaining rows (< 70,000). seems non-trivial.
i know manually calculating size of n+1
dataframe, removing it, , using split
function in following way:
d <- split(my_data_frame,rep(1:100,each=70,000))
but have multiple large dataframes , doing these calculations tedious. there alternative solution?
how this:
df <- data.frame(x = 1:723500, y = runif(7235000)) split(df, rep(1:100, each = round(nrow(df) / 100, -4)))
or abstracting more:
num_dfs <- 100 split(df, rep(1:num_dfs, each = round(nrow(df) / num_dfs, -4)))
you may want consider caret
package such as: caret::createfolds(df$x)
Comments
Post a Comment