user3755880
user3755880

Reputation: 375

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

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!

Upvotes: 4

Views: 3986

Answers (1)

RDGuida
RDGuida

Reputation: 566

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)]<-""

Upvotes: 2

Related Questions