Gib*_*Gay 16 r matrix data.table
我有一个~2,000x20,000的数据,我如何在速度和内存方面有效地转换data.table()为matrix高效?
我试过m = as.matrix(dt)但很多警告需要很长时间.df = data.frame(dt)需要很长时间并导致达到内存限制.
有没有有效的方法来做到这一点?或者,只是data.table中的一个函数,它返回dt矩阵形式(根据需要使用glmnet包输入统计模型)?
简单地包装到as.matrix会给我以下错误:
x = as.matrix(dt)
Error: cannot allocate vector of size 2.9 Gb
In addition: Warning messages:
1: In unlist(X, recursive = FALSE, use.names = FALSE) : Reached total allocation of 8131Mb: see help(memory.size)
2: In unlist(X, recursive = FALSE, use.names = FALSE) : Reached total allocation of 8131Mb: see help(memory.size)
3: In unlist(X, recursive = FALSE, use.names = FALSE) : Reached total allocation of 8131Mb: see help(memory.size)
4: In unlist(X, recursive = FALSE, use.names = FALSE) : Reached total allocation of 8131Mb: see help(memory.size)
Run Code Online (Sandbox Code Playgroud)
我的操作系统:我有64位Windows7和8gb内存,我的Windows任务管理器显示Rgui.exe以前占用的空间超过4GB,但仍然很好.
尝试:
result <- as.matrix(tidytext::cast_sparse(dat_table,
column_name_of_rows,
column_name_of_columns,
column_name_of_values))
Run Code Online (Sandbox Code Playgroud)
它应该非常高效和快速。