The decimal point in the fread file, data.table

I would like to use fread from data.table, but I get a warning associated with the decimal point [here a ',' instead of '.']. I usually use ".", But in some cases for a file I need to import files with "," as a decimal point.

In read.csv, I can set the decimal point separator:

df <- read.csv("mydata.csv", sep=";", dec=",") 

How to do this in the fread function in data.table? with

 df=fread('mydata.csv',sep=';') 

A warning message appears:

 Warning message: In fread("mydata.csv", : Bumped column 7 to type character on data row 86, field contains '4,5'. 

where 4,5 is the value that would be correctly read as "4.5" with sep = ',' in read.csv.

 sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 [6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C 
+6
source share
1 answer

Oct 2014 update : now in version 1.0.5

fread now accepts dec=',' (and other non-. decimal separators), # 917 . A new paragraph has been added to ?fread . If you are in a country that uses dec=',' then it should work. If not, you will need to read the paragraph for an additional step. If it somehow breaks dec='.' , this new feature can be disabled using options(datatable.fread.dec.experiment=FALSE) .



Previous answer ...

Since you are using Linux using data.table 1.8.11, you can do the following:

 fread("sed 's/,/./g' yourfile", sep = ";") 

(actually I don't think you even need to specify sep here)

+6
source

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


All Articles