使用`data.table :: fread`读取R中的某些数字作为NA [英] Read in certain numbers as NA in R with `data.table::fread`
问题描述
我正在阅读由另一个程序创建的某些文件。该程序填充缺少值为 -99.9
的条目。
我正在加速一些代码使用base data.table $ c>中的
read.table()
至 fread()
$ c>包在这些数据文件中读取。我可以在 read.table
中使用 na.strings = c(-99.9)
,但 fread
似乎不接受 na.strings
的数字参数。字符串对应 na.strings = c( - 99.9)
,不工作,并给出错误:'na.strings'是类型'
。
我可以使 fread
$ c> -99.9 as NA
?
如果您以 dt
的形式阅读,请将这些值更改为NA。
dt [dt == -99.9]< - NA
p>
I am reading in some files created by another program. The program populates entries with missing values with the number -99.9
.
I am speeding up some code from using base read.table()
to fread()
from the data.table
package to read in these data files. I am able to use na.strings=c(-99.9)
in read.table
, but fread
does not seem to accept numeric arguments for na.strings
. The string counterpart, na.strings=c("-99.9")
, does not work, and gives me the error: 'na.strings' is type '
.
Can I make fread
read in the number -99.9
as NA
?
If you read it in as dt
change those values to NA afterwards.
dt[dt == -99.9] <- NA
problem solved?
这篇关于使用`data.table :: fread`读取R中的某些数字作为NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!