r - fread 从大文件中读取前 n 行
问题描述
使用fread
. 看起来是内存问题。我尝试使用nrows=1000
. 但没有运气。使用Linux
file ok but could not memory map it. This is a 64bit process. There is probably not enough contiguous virtual memory available.
下面的代码可以用read.csv
下面使用的所有选项替换吗?它有帮助吗?
rdata<- fread(
file=csvfile, sep= "|", header=FALSE, col.names= colsinfile,
select= colstoselect, key = "keycolname", na.strings= c("", "NA")
, nrows= 500
)
解决方案
另一种解决方法是使用 shell 命令获取前 500 行:
rdata<- fread(
cmd = paste('head -n 500', csvfile),
sep= "|", header=FALSE, col.names= colsinfile,
select= colstoselect, key = "keycolname", na.strings= c("", "NA")
)
不过,我不知道为什么nrows
不起作用。
推荐阅读
- cython - 在 Cython 中键入字符串列表
- ios - React-Native:在项目或这些目录中找不到 React
- mysql - 如何在mysql中的group by中查找组内的重复项?
- c# - 错误:无法在此范围内声明名为“模型”的局部变量
- python - 将变量整数转换为列表中的个位数单词形式
- python - 使用 .loc 选择多索引级别的重复值
- bash - 通过目录停止文件的无限循环
- ipython - 在 cmd.exe 下的 IPython 中取消缩进代码块?
- vba - Excel VBA - 将电子邮件移动到不同的文件夹
- windows - Batch:如何在 CALL 函数内部正确使用 CHOICE?