对于大列向量使用`fread()`的内存要求

问题描述 投票:1回答:1

我有一个人类可读的文件,包含10亿个双打,全部写在一行(10亿列)。

文件本身只有8G左右,我正在使用

fread("filename.data", sep=" ", header=FALSE, data.table=TRUE, showProgress=TRUE)

将它们加载到R会话中。该脚本将永远被“杀死”,我从showProgress获得的大部分信息都是

*抓住了segfault *地址0x7efc7bed2010,导致'内存未映射'

我过去使用相同的方法加载了更大的文件(原始大小),但可能采用“矩阵形式”并且列数较少。我猜测data.table需要存储10亿个列名,这会耗费大量内存......这是正确的吗?

  1. 有没有办法让fread直接进入行向量(与阅读后的转置相反)?
  2. 这些数据是否可以挽救,还是我需要将其重新编写为行向量?
r data.table fread
1个回答
0
投票

作为单列的finge singele row?

干得好..

library(data.table)

#read using default separators
fread('v1,v2,v2,v3
this, is, a, test
of, fread,one,line')

#      v1    v2  v2   v3
# 1: this    is   a test
# 2:   of fread one line

#read one column per line/row
fread('v1,v2,v2,v3
this, is, a, test
      of, fread,one,line', sep = "", header = FALSE)

#                    V1
# 1:        v1,v2,v2,v3
# 2:  this, is, a, test
# 3: of, fread,one,line
© www.soinside.com 2019 - 2024. All rights reserved.