2

I have recently upgraded my data.table version to 1.11.4 and am running into an issue. It is similar to the issue raised below:

Blank space not recognised as NA in fread

In the comments, however, it is simply stated that "I guess this was introduced with data.table version 1.11.0 (see github.com/Rdatatable/data.table/blob/master/NEWS.md, section 1) quote: "We would like ,,=>NA for consistency with numeric types, and ,"",=>empty string to be the standard default for fwrite/fread character columns so that fread(fwrite(DT))==DT without needing any change to any parameters."

I've read through the documents below and tried using "options(datatable.fread.na.strings="NA")" but still get the character column read in as blanks instead of NA. There has to be a workaround for this?

Example:

library(data.table)
x1 <- c("","","")
x2 <- c("1006678566","","1011160152")
x3 <- c("","ac","")
x4 <- c("","2","3")
df <- cbind.data.frame(x1,x2,x3,x4)
write.csv(df,"tr.csv")

tr1 <- fread("tr.csv", header=T, fill = T,
sep= ",", na.strings = c("",NA), data.table = F,stringsAsFactors = FALSE)

tr2 <- read.table("tr.csv", fill = TRUE, header=T, sep= ",", na.strings = c(""," ", NA), stringsAsFactors = FALSE)
lmo
  • 37,904
  • 9
  • 56
  • 69
sewarner
  • 21
  • 2

0 Answers0