【发布时间】:2020-12-26 08:15:09
【问题描述】:
我正在使用 dplyr 进行一些数据操作,并使用我的巨大数据 (b) 框架。
我已经能够成功处理较小的数据子集。我想我的问题在于我的数据框的大小。
我的数据框有 400 万行和 34 列。
我的代码如下:
df<-b %>%
group_by(Id) %>%
mutate(numberoflead = n(),#lead sayısı
lastcreateddateoflead=max(CreatedDate),#last date of lead
firstcreateddateoflead=min(CreatedDate),#first date of lead
lastcloseddate=max(Kapanma.tarihi....),#last closed date of kapanm tarihi
yas=as.Date(lastcloseddate)-as.Date(firstcreateddateoflead),#yas
leadduration=as.Date(lastcreateddateoflead)-as.Date(firstcreateddateoflead)) %>%#lead duration
inner_join(b %>%
select(Id, CreatedDate, lasttouch = Lead_DataSource__c),
by = c("Id" = "Id", "lastcreateddateoflead" = "CreatedDate")) %>% #lasttouch
inner_join(b %>%
select(Id, CreatedDate, firsttouch = Lead_DataSource__c),
by = c("Id" = "Id", "firstcreateddateoflead" = "CreatedDate")) %>% #firsttouch
inner_join(b %>%
select(Id, Kapanma.tarihi...., laststagestatus = StageName),#laststagestatus
by = c("Id" = "Id", "lastcloseddate" = "Kapanma.tarihi...."))
它在我的数据帧的较小子集上运行良好,但是当我将上面的代码运行到我的完整数据帧时, 它运行了很长时间并最终崩溃。我认为问题可能出在我的数据框的 400 万行
有人对如何做到这一点有任何建议吗?非常感谢您的帮助!
【问题讨论】:
-
试试
data.table,即setDT(b)[, c('numberoflead', 'lastcreateddateoflead') := .(.N, max(CreatedDate)), Id] -
还可以查看
dtplyr(数据表后端到dplyr)和dbplyr(SQL 数据库后端到dplyr) -
@BenBolker,我已经尝试过使用 dtplyr 但现在我得到了这个错误;错误:无法分配大小为 17.5 Mb 的向量。有什么想法吗?
-
这意味着您仍然遇到内存限制。你有多少内存?您可能需要内存不足的解决方案(例如
dbplyr或查看 cran.r-project.org/web/views/HighPerformanceComputing.html
标签: r dplyr large-data