R: reading in a .csv turns all "" (blank spaces) to NA

3.6k views Asked by At

I have a data set in which I converted all "~" values to blank spaces "", and when I use the View() function to view the data set, I can clearly see the blank spaces. However, after I save my modified data frame as a .csv file via write.csv and read it again in R via read.csv, all the blank spaces are somehow changed to NA values. I tried to change all my NA values back to the blank spaces again, but the same problem occurs when I save as csv and read it again.

Any help would be appreciated!

1

There are 1 answers

1
RDGuida On BEST ANSWER

there is the parameter na you can specify

write.csv(data, "data.csv", row.names=FALSE, na="")

When you read it again you need to convert NA to blank everytime though

data[is.na(data)]<-""