【发布时间】:2014-04-14 12:08:08
【问题描述】:
我正在将一个大的 .csv 文件导入 R(大约 50 万行),所以我一直在尝试使用 data.table 包中的 fread() 作为 read.table() 和读取的更快替代方案.csv()。但是, fread() 返回一个数据框,其中包含一行内的行中的所有数据,即使它具有正确的列数。我发现 2013 年的错误报告显示这与 integer64 数据类有关:
http://r-forge.r-project.org/tracker/index.php?func=detail&aid=2786&group_id=240&atid=975
是否有任何解决方法或方法来解决这个问题?
我尝试读取的 .csv 文件完全是 0 到 10000 之间的整数,没有丢失数据。我在 Windows 7 计算机上使用 R 版本 2.15.2,data.table 包的版本为 1.8.8。
我运行的代码是:
require(data.table)
fread("pre2012_alldatapoints.csv", sep = ",", header= TRUE)-> pre
head(pre)
1: 1 22 -105 22 -105
2: 2 22 -105 22 -105
3: 3 20 -105 20 -105
4: 4 21 -105 21 -105
5: 5 21 -105 21 -105
6: 6 21 -105 21 -105
dim(pre)
[1] 12299 5 #dim returns the correct number of dimensions
#this is a subset of the file I want to import that I've confirmed imports correctly with read.csv
pre[,1]
[1] 1 #but trying to print a column returns this
length(pre[,1])
[1] 1 #and length for any column returns a row length of 1
【问题讨论】:
-
pre[ , 1]现在返回第一列的列子集,正如 OP 在此处最初预期的那样
标签: r import data.table fread