Fread in R imports a large CSV file as a single-line data frame

I am importing a large .csv file into R (about 0.5 million lines), so I tried to use fread () from the data.table package as a faster alternative to read.table () and read.csv (). However, fread () returns a data frame with all the data from the rows on the same row, even if it has the correct number of columns. I found a 2013 error report showing that this is due to the integer64 data class:

http://r-forge.r-project.org/tracker/index.php?func=detail&aid=2786&group_id=240&atid=975

Are there any fixes or ways around this?

The .csv file I'm trying to read contains integers ranging from 0 to 10,000 without missing data. I am using R version 2.15.2 on a computer running Windows 7 with version 1.8.8 of the data.table package.

The code I run is:

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

Many thanks for your help!

+8
source share
1 answer

freadcreates data.table. The package data.tablecomes with several vignettes.

Your exact problems are addressed in FAQ 1.1 from the data.table FAQ - the very first FAQ!

By default, the second statement [.data.tableis an expression evaluated within the data area. table

pre[,1] 1 pre. 1 1. " , with=FALSE pre[,1,with=FALSE]

+8

Source: https://habr.com/ru/post/1531091/


All Articles