问题描述
我想使用data.table中的fread,但会收到与小数点有关的警告[这里是‘,’而不是’。]。通常我使用'。',但是在某些情况下,我必须使用','作为小数点导入文件。
I would like to use fread from data.table, but get a warning related to the decimal point [here a ',' instead of a '.']. Normally I use '.', but in some cases the file I have to import files with ',' as decimal point.
在read.csv中,我可以设置小数点分隔符:
In read.csv I can set the decimal point separator:
df <- read.csv("mydata.csv", sep=";", dec=",")
如何在data.table的fread函数中执行此操作?与
How can I do this in the fread function in data.table? with
df=fread('mydata.csv',sep=';')
我收到警告消息:
Warning message: In fread("mydata.csv", : Bumped column 7 to type character on data row 86, field contains '4,5'.
,其中4,5是在read.csv中正确读取为'4.5'并且带有sep ='的值。
, where 4,5 is the value the would have been read in correctly 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
推荐答案
2014年10月更新:现在在v1中。 9.5
Update Oct 2014 : Now in v1.9.5
上一个答案...
Previous answer ...
由于您使用的是Linux,因此使用 data.table 1.8.11您可以执行以下操作:
Since you're on Linux, using data.table 1.8.11 you can do the following:
fread("sed 's/,/./g' yourfile", sep = ";")
(实际上,我认为您甚至不需要指定 sep 此处)
(actually I don't think you even need to specify sep here)
这篇关于fread,data.table中的小数点设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!