I have a large data.table object (1M rows and 220 columns) and I want to replace all blanks ('') with NA. I found a solution in this Post, but it's extremely slow for my data table (takes already over 15mins) Example from the other post:
data = data.frame(cats=rep(c('', ' ', 'meow'),1e6),
dogs=rep(c("woof", " ", NA),1e6))
system.time(x<-apply(data, 2, function(x) gsub("^$|^ $", NA, x)))
Is there a more data.table fast way to achieve this?
Indeed the provided data does not look much like the original data, it was just to give an example. The following subset of my real data gives the CharToDate(x) error:
DT <- data.table(ID=c(10),DEFAULT_DATE=as.Date("2012-07-31"),value='')
system.time(DT[DT=='']<-NA)