[英]Importing large csv file in R, error in read.csv.ffdf
我想导入一个有故障的大文件(40Mrows x 4columns)。 我尝试使用sqldf后最终使用ffbase
我尝试了base::read.csv
:失败了。 我尝试了sqldf::sqldf
:它也失败了,说它不能再分配了。
我只是想复制ffbase小插图中给出的示例。
R) x <- data.frame(log=rep(c(FALSE, TRUE), length.out=26), int=1:26, dbl=1:26 + 0.1, fac=factor(letters), ord=ordered(LETTERS), dct=Sys.time()+1:26, dat=seq(as.Date("1910/1/1"), length.out=26, by=1))
R) x <- x[c(13:1, 13:1),]
R) csvfile <- tempPathFile(path=getOption("fftempdir"), extension="csv")
R) write.csv(x, file=csvfile, row.names=FALSE)
R) y <- read.csv(file=csvfile, header=TRUE)
R) y
log int dbl fac ord dct dat
1 FALSE 13 13.1 m M 2012-11-26 11:21:29.15763 1910-01-13
2 TRUE 12 12.1 l L 2012-11-26 11:21:28.15763 1910-01-12
3 FALSE 11 11.1 k K 2012-11-26 11:21:27.15763 1910-01-11
4 TRUE 10 10.1 j J 2012-11-26 11:21:26.15763 1910-01-10
...
23 TRUE 4 4.1 d D 2012-11-26 11:21:20.15763 1910-01-04
24 FALSE 3 3.1 c C 2012-11-26 11:21:19.15763 1910-01-03
25 TRUE 2 2.1 b B 2012-11-26 11:21:18.15763 1910-01-02
26 FALSE 1 1.1 a A 2012-11-26 11:21:17.15763 1910-01-01
# ---- !!!!! HERE !!!! ---- #
R) ffx <- read.csv.ffdf(file=csvfile, header=TRUE)
Erreur dans ff(initdata = initdata, length = length, levels = levels, ordered = ordered, : vmode 'character' not implemented
我不明白
你有什么见识?
您可能需要按如下所示传递参数colClasses。 就像使用普通的read.csv一样
ffx <- read.csv.ffdf(file=csvfile, header=TRUE, colClasses = c("logical","integer","numeric","factor","factor","POSIXct","Date"))
抱歉,我迟到了,我最近3天无法访问R。 这是read.csv
一些其他代码
R) setAs("character","myDate", function(from) as.Date(from, format="%d/%m/%y") )
R) system.time(data <- read.csv(file=filePath, sep=";", stringsAsFactors=TRUE, colClasses=c("factor","factor","numeric","myDate"), nrows=10));
utilisateur système écoulé
0 0 0
R) system.time(data <- read.csv(file=filePath, sep=";", stringsAsFactors=TRUE, colClasses=c("factor","factor","numeric","myDate")));
Erreur : impossible d'allouer un vecteur de taille 250.0 Mo
Timing stopped at: 236.2 4.92 333.3
=>因此, read.csv
无法处理该行数。
对read.csv.sql
相同测试,该测试仅是500行的sqldf
的包装器。
R) system.time(data <- read.csv.sql(filePath, dbname = tempfile(), header = T, row.names = F, sep=";"));
utilisateur système écoulé
0.07 0.00 0.07
顺便说一句,请注意, nbrows
选项是!NOT WORKING!... abd,您不能指示colClasses
参数...
R) system.time(data <- sqldf("select * from f", dbname = tempfile(), file.format = list(header = T, row.names = F, sep=";")));
Erreur : impossible d'allouer un vecteur de taille 500.0 Mo
Timing stopped at: 366.8 42.45 570.2
对于整个表,它崩溃了……奇怪,因为它应该作为大数据的参考...
最后使用ff
包,进行50行
R) system.time(data <- read.csv.ffdf(file=filePath, header=TRUE, nrows=50, colClasses=c("factor","factor","numeric","myDate"),sep=";"))
utilisateur système écoulé
0.02 0.00 0.03
请注意, head(data)
也有一个错误,它不能正确显示列...
对于整个桌子...它的工作...!烟花!
R) system.time(data <- read.csv.ffdf(file=filePath, header=TRUE, colClasses=c("factor","factor","numeric","myDate"),sep=";"))
utilisateur système écoulé
409.69 14.42 547.75
对于36M行表
R) dim(data)
[1] 36083010 4
因此,我建议ff
包加载大数据集
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.