I am trying to split a relatively large data.table into roughly equal parts to output the names into csv files. I've already implemented a solution based on Split data.table into roughly equal parts
library(data.table)
library(plyr)
dt <- data.table(Name = letters)
bins <- 5
dt[order(-rank(Name)), Split.ID := as.integer(runif(.N,0,bins))]
d_ply(dt[order(-rank(Name))], .(Split.ID),
function(sdf) write.csv(x = sdf[,1] , file = paste0("Output/test.",sdf$Split.ID[[1]],".csv"), quote = FALSE, row.names = FALSE, eol = ", "))
The problem with this solution is that the ordering of the names in the csv files is alphabetical, but because of the randomness of the Split.ID it is not preserved for all csv files.