0

Data

I have a very big data frame with more than 400.000 rows and I want to split them into smaller data frames based on their Customer ID. I know there are some questions about splitting data and I did try, it worked though it just 1 by 1 split the data frame. I want to make it automatically splitting all since there are more than 100.000 subsets. So can anyone help me with this? Thank you so much

Here is my code

List <-lapply(unique(CheckinHistory$CustomerID), function(x) CheckinHistory[CheckinHistory$CustomerID == x,])
purrr:::reduce(a[1], rbind.data.frame) 
for(i in 1:114420)
  a[i] <- purrr:::reduce(List[i], rbind.data.frame)

R doesn't understand and claims a[i] doesn't exist. But if I code

List <-lapply(unique(CheckinHistory$CustomerID), function(x) CheckinHistory[CheckinHistory$CustomerID == x,])
purrr:::reduce(a[1], rbind.data.frame) 
a[1] <- purrr:::reduce(List[1], rbind.data.frame)

Then it works but there are more than 100.000 subsets of this data frame so I cant code them 1 by 1 like that way. Once again, many thanks!

rawr
  • 20,481
  • 4
  • 44
  • 78
  • Please provide a small and reproducible example of your data along with your expected output. Images are not the right way to share data. Read about [how to give a reproducible example](http://stackoverflow.com/questions/5963269) – Ronak Shah May 11 '21 at 02:23
  • What's wrong with `split(CheckinHistory, CheckinHistory$CustomerID)`? (I think the "tidyverse" equivalent would be `%>% group_by` – IRTFM May 11 '21 at 02:26
  • @IRTFM It works but the main problem is that all of the subsets are .list file. I want to convert them all to df and export csv file. "purrr:::reduce(a[1], rbind.data.frame) a[1] <- purrr:::reduce(List[1], rbind.data.frame)" that is why I have this function here. But it doesnt work -.- – Đặng Bá Thiện Phúc May 11 '21 at 04:00

0 Answers0