How can I get fread() to set "" to a NA for all variables including character variables?
I am importing a .csv file where missing values are empty strings (""; no space). I want "" to be interpreted as missing value NA and tried `na.strings = "" without success:
data <- fread("file.csv", na.strings = "")
unique(data$character_variable)
# [1] "abc" "def" ""
On the other hand, when I use read.csv with na.strings = "", the "" are turned into NAs, even for character variables. This is the result I want.
data <- read.csv("file.csv", na.strings = "")
unique(data$character_variable)
# [1] "abc" "def" NA
versions
- R version 3.6.1 (2019-07-05)
- data.table_1.12.8