【发布时间】:2017-02-02 09:16:42
【问题描述】:
我在r中的“大数据处理”中比较新,希望寻找一些关于如何处理50 GB csv文件的建议。当前问题如下:
表格看起来像:
ID,Address,City,States,... (50 more fields of characteristics of a house)
1,1,1st street,Chicago,IL,...
# the first 1 is caused by write.csv, they created an index raw in the file
我想查找属于加利福尼亚州旧金山的所有行。这应该是一个简单的问题,但是 csv 太大了。
我知道我在 R 中有两种方法,另一种方法是使用数据库来处理它:
(1) 使用 R 的 ffdf 包:
自从上次保存文件以来,它一直在使用 write.csv,它包含所有不同的类型。
all <- read.csv.ffdf(
file="<path of large file>",
sep = ",",
header=TRUE,
VERBOSE=TRUE,
first.rows=10000,
next.rows=50000,
)
控制台给了我这个:
Error in ff(initdata = initdata, length = length, levels = levels, ordered = ordered,
: vmode 'character' not implemented
通过网上搜索,我发现了几个不适合我的情况的答案,我无法真正理解如何将“字符”转换为“因子”类型。
然后我尝试使用 read.table.ffdf,这更加灾难。我找不到那个可靠的指南。
(2) 使用 R 的 readline:
我知道这是另一种好方法,但找不到有效的方法。
(3) 使用 SQL:
我不知道如何将文件转换为 SQL 版本,以及如何处理,如果有好的指南我想试试。但总的来说,我想坚持使用 R。
感谢您的回复和帮助!
【问题讨论】:
-
看看this answer是否有帮助。
-
in v. 类似于 ^^ 链接stackoverflow.com/questions/26861951/…
-
我会检查一下谢谢!