Read in certain numbers as NA in R with `data.table::fread`

夙愿已清 提交于 2019-12-24 15:43:46

问题


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?


回答1:


If you read it in as dt change those values to NA afterwards.

dt[dt == -99.9] <- NA

problem solved?



来源:https://stackoverflow.com/questions/22331552/read-in-certain-numbers-as-na-in-r-with-data-tablefread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!