When writing out a zoo object to a CSV file using write.zoo(), I would actually like to drop decimal precision from the default of 14 to just 3. However, even with setting scipen & digits in options(), I have not been able to drop the precision in output.
Here is a sample code to illustrate the issue.
blah <- zoo(cbind(c(1.590833333333335, NA), c(NA, 21.590833333333337)))
index(blah) <- c("Dec 1985", "Dec 1986")
colnames(blah) <- c("FooHeader", "BarHeader")
options(scipen = 3, digits = 3)
write.zoo(blah, file = "blah.csv", sep = ",")
If I open the blah.csv
file, I see
"Index","FooHeader","BarHeader"
"Dec 1985",1.59083333333334,NA
"Dec 1986",NA,21.5908333333333
But what I would really want to see is
"Index","FooHeader","BarHeader"
"Dec 1985",1.591,NA
"Dec 1986",NA,21.591
How do I go about making this happen? Thanks a bunch in advance!
Note: I am aware that by dropping the precision, if I read the data into the R again, I would still lose the precision. That's fine. I can live with that.