读取R中的int向量,每个int 4个字节

时间:2017-12-04 23:45:45

标签: r vector binary-data

我有一个1 GB的文件,它是一个250M元素的向量,每个都是一个4字节 - int(用C ++保存)。

如何将其加载到R向量中?这是自然的方式吗?

f = file("myfile.dat")
readBin(f, integer(), n = 250000000, size = 4, endian = "little")

1 个答案:

答案 0 :(得分:1)

实际上问题只是开放binary模式:

f = file("myfile.dat", open="rb")
readBin(f, integer(), n = 250000000, size = 4, endian = "little")