I'm trying to export some data, however it contains blank values in some spaces. The data I imported (which is to be imported slightly modified, then exported) contains these blank, null values. After I export the file, these values are converted into blank strings. I want these values to stay as they were when I imported them.
They don't appear any different from a blank string in Excel, but when viewed in Notepad, the blanks appear as ,"", versus ,, as they do before being imported.
This appears to be exactly what I'm looking for, however, it doesn't produce the desired (or described) result.
I've tried using na = ""
and na = NULL
in both write.csv()
and write.table()
. Is there a way of accomplishing this? I'll include a few examples below of what I've tried, they all produce either NAs or ""s where I'd like empty values in my CSV.
(It's worth noting, I've included both NA
s and ""
s in this df, but I could easily standardize these values, so long as I can convert one to empty/null values in the CSV.)
df <- data.frame(c(1,NA,3,4), c(1,2,"",4))
write.table(df, "TestData.csv",
na = "",
row.names = FALSE,
col.names = FALSE,
append = FALSE,
sep = ",")
write.csv(df, "TestData.csv", na = character(0))
write.csv(df, "TestData.csv", na = "")
write.csv(df, "TestData.csv", na = NULL)