Ozg*_*kın 6 r large-data dplyr
我正在用 dplyr 用我的大量数据进行一些数据操作(b ) 框架进行一些数据操作。\n我已经能够成功地处理较小的数据子集。我想我的问题是数据框的大小。
我的数据框有 400 万行和 34 列。
\n我的代码如下:
\ndf<-b %>%\n group_by(Id) %>%\n mutate(numberoflead = n(),#lead say\xc4\xb1s\xc4\xb1\n lastcreateddateoflead=max(CreatedDate),#last date of lead\n firstcreateddateoflead=min(CreatedDate),#first date of lead\n lastcloseddate=max(Kapanma.tarihi....),#last closed date of kapanm tarihi\n yas=as.Date(lastcloseddate)-as.Date(firstcreateddateoflead),#yas\n leadduration=as.Date(lastcreateddateoflead)-as.Date(firstcreateddateoflead)) %>%#lead duration\n inner_join(b %>% \n select(Id, CreatedDate, lasttouch = Lead_DataSource__c),\n by = c("Id" = "Id", "lastcreateddateoflead" = "CreatedDate")) %>% #lasttouch\n inner_join(b %>% \n select(Id, CreatedDate, firsttouch = Lead_DataSource__c),\n by = c("Id" = "Id", "firstcreateddateoflead" = "CreatedDate")) %>% #firsttouch\n inner_join(b %>% \n select(Id, Kapanma.tarihi...., laststagestatus = StageName),#laststagestatus\n by = c("Id" = "Id", "lastcloseddate" = "Kapanma.tarihi...."))\nRun Code Online (Sandbox Code Playgroud)\n它在我的数据帧的较小子集上运行良好,但是,当我将上面的代码运行到我的完整数据帧时,\nit 运行很长时间并最终崩溃。我认为问题可能出在我的数据框的 400 万行上
\n有人对如何执行此操作有任何建议吗?非常感谢您的帮助!
\n小智 1
我最近遇到了类似的问题,代码大小相似。我认为你的问题是R内存空间的大小。您可以在 R 编辑器中检查全局环境之上的容量。我的内存因大数据量而超载,然后程序经常崩溃。
我的解决方案是编写两段单独的代码。在第一个中,我将所有数据集合并到一个文件中,并以以下内容结束代码
saveRDS(file, file = "filename.Rds") # save as one object to save work space in working directory as R data file
Run Code Online (Sandbox Code Playgroud)
然后关闭文件,手动清除 R 内存(单击“释放未使用的 R 内存”)并启动一个新代码,在其中加载之前创建的文件
setwd("PathWhereTheFileIsSaved") # set working directory
complete <- readRDS(file = "filename.Rds") # load previously in code 1 created data
Run Code Online (Sandbox Code Playgroud)
之后,我的代码可以正常工作,而不会导致内存超载。