fread
function from data.table package reads large csv files faster than the read.cvs
function. But as you can see from the output of a data frame from both routines are different for the "device _id" column (see last 3 digits). Why? Is there a parameter in these functions to read them correctly? Or this is a normal behavior for fread
? (it reads this datafile 10x faster though).
# Read file
p<-fread("C:\\User\\Documents\\Data\\device.csv",sep=", integer64="character" )
> str(p)
Classes ‘data.table’ and 'data.frame': 187245 obs. of 3 variables:
$ device_id : Factor w/ 186716 levels "-1000025442746372936",..: 89025 96789 140102 123523 45208 118633 32423 22215 54410 81947 ...
$ phone_brand : Factor w/ 131 levels "E<U+4EBA>E<U+672C>""| __truncated__,"E<U+6D3E>""| __truncated__,..: 52 52 16 10 16 32 52 32 52 14 ...
$ device_model: Factor w/ 1598 levels "1100","1105",..: 1517 750 561 1503 537 775 753 433 759 983 ...
- attr(*, ".internal.selfref")=<externalptr>
> head(p)
device_id brand device_model
1: -8890648629457979026 <U+5C0F><U+7C73> <U+7EA2><U+7C73>
2: 1277779817574759137 <U+5C0F><U+7C73> MI 2
3: 5137427614288105724 <U+4E09><U+661F> Galaxy S4
4: 3669464369358936369 SUGAR <U+65F6><U+5C1A><U+624B><U+673A>
5: -5019277647504317457 <U+4E09><U+661F> Galaxy Note 2
6: 3238009352149731868 <U+534E><U+4E3A> Mate
# Read file
p<-read.csv("C:\\Users\\Documents\\Data\\device.csv",sep=",")
# Convert device_id to character
> p$device_id<-as.character(p$device_id)
> str(p)
'data.frame': 187245 obs. of 3 variables:
$ device_id : chr "-8890648629457979392" "1277779817574759168" "5137427614288105472" "3669464369358936576" ...
$ phone_brand : chr "<U+5C0F><U+7C73>""| __truncated__ "<U+5C0F><U+7C73>""| __truncated__ "<U+4E09><U+661F>""| __truncated__ "SUGAR" ...
$ device_model: chr "<U+7EA2><U+7C73>""| __truncated__ "MI 2" "Galaxy S4" "<U+65F6><U+5C1A><U+624B><U+673A>""| __truncated__ ...
> head(p)
device_id brand device_model
1 -8890648629457979392 <U+5C0F><U+7C73> <U+7EA2><U+7C73>
2 1277779817574759168 <U+5C0F><U+7C73> MI 2
3 5137427614288105472 <U+4E09><U+661F> Galaxy S4
4 3669464369358936576 SUGAR <U+65F6><U+5C1A><U+624B><U+673A>
5 -5019277647504317440 <U+4E09><U+661F> Galaxy Note 2
6 3238009352149731840 <U+534E><U+4E3A> Mate