问题
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