ivot_longer 具有非常大的 data.frame,内存有效的方法
我有一个包含 1100 万行医院数据的 data.frame
。
Columns: ID (chr), outcome (1|0), 20x ICD-10 codes (chr).
Rows: 10.6 million
我希望使数据整洁,以便将诊断代码建模为二进制结果。
我通常会使用 pivot_longer
或 Base R aggregate
函数,但生成的 data.frame
很大,而且由于内存(32GB RAM、运行最新 R x64 的 Windows 服务器)。
我将分别拆分 data.frame
和 pivot_longer
并手动添加列以允许绑定 data.frame
的后面,或者分别对每个拆分的 data.frame
进行建模。
有没有一种方法可以用来减少数据大小或实现我所缺少的类似目标?
I have a data.frame
of hospital data with 11 million rows.
Columns: ID (chr), outcome (1|0), 20x ICD-10 codes (chr).
Rows: 10.6 million
I wish to make the data tidy to allow modelling of diagnostic codes to a binary outcome.
I would normally use pivot_longer
or Base R aggregate
function, but the resulting data.frame
is huge and my machine struggles, due to memory (32gb RAM, windows server running latest R x64).
I am going to split the data.frame
and pivot_longer
for each and manually add columns to allow binding data.frame
's after, or to model each split data.frame
separately.
Is there a method I could use instead to reduce the data size or achieve a similar objective which I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
data.table::melt
代替:library(data.table) 提供了基础 R 的 data.frame 的高性能版本(注重速度和内存效率)。
另请参阅此相关基准测试。
Try using
data.table::melt
instead:library(data.table) provides a high-performance version of base R's
data.frame
(focus on speed and memory efficiency).Please also see this related benchmark.