I have a dataframe in R with 11M rows and 46 columns. Some of the fields contain empty strings (""). I need to replace those empty strings with NAs because write.dta
(in the foreign
package) can't handle empty strings.
My for-loop, however, takes very long (around 15 minutes per column; sometimes R/ entire system crashes). I'm running RStudio (R 3.0.2) on a 8GB RAM Mac. Does anyone know of a faster way?
for (i in 1:46){
if (length(which(myDF[,i]==""))!=0) {
myDF[,i][which(myDF[,i]=="")]<-NA
}
}