analyticsPierce
analyticsPierce

Reputation: 3025

Using read.csv, empty fields have NA added to data.frame

I am using read.csv to import a file that contains some columns with empty cells. I need these cells to remain empty and not contain any values.

However, an NA is getting added everytime I import. I have tried variations of na.strings (like na.strings="NULL" or na.strings="") to no avail.

Is there a simple way to force the observations to remain empty?

Any advice is appreciated.

Upvotes: 5

Views: 14590

Answers (1)

Brandon Bertelsen
Brandon Bertelsen

Reputation: 44648

After the import, try this:

x[is.na(x)] <- c("") ## Refills NA with blank character.

This converts the column to character but if you already have mixed strings I imagine it already is.

Upvotes: 7

Related Questions