Dear list, I have an irregular time series saved and exported as a zoo object. What is the trick to force zoo to ignore the missing dates when reading it back in? Thanks.> str(g)?zoo? series from 1948-11-02 to 2012-11-06 Data: num [1:14881, 1:8] 1 0 0 0 0 0 0 0 0 0 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:8] "session" "midterm" "day.of.wk" "elapsed" ... Index: Class 'Date' num [1:14881] -7730 -7303 -7302 -7301 -7300 ...> write.zoo(g, file = "gdata.txt", index.name = "date", append = F, quote = T, sep = ",")> h <- read.zoo("gdata.txt", sep = ",", format = "Y-%m-%d")Error in read.zoo("gdata.txt", sep = ",", format = "Y-%m-%d") : index contains NAs
Without a reproducible example, i.e. the input file, one can't say much but in general you could read it in using read.table, remove the NAs and then convert it to zoo. On Wed, Feb 25, 2009 at 11:29 PM, Rob Denniker <bearmarketsrule at inbox.com> wrote:> Dear list, > > I have an irregular time series saved and exported as a zoo object. What is the trick to force zoo to ignore the missing dates when reading it back in? Thanks. > >> str(g) > ?zoo? series from 1948-11-02 to 2012-11-06 > ?Data: num [1:14881, 1:8] 1 0 0 0 0 0 0 0 0 0 ... > ?- attr(*, "dimnames")=List of 2 > ?..$ : NULL > ?..$ : chr [1:8] "session" "midterm" "day.of.wk" "elapsed" ... > ?Index: Class 'Date' ?num [1:14881] -7730 -7303 -7302 -7301 -7300 ... > >> write.zoo(g, file = "gdata.txt", index.name = "date", append = F, quote = T, sep = ",") > >> h <- read.zoo("gdata.txt", sep = ",", format = "Y-%m-%d") > Error in read.zoo("gdata.txt", sep = ",", format = "Y-%m-%d") : > ?index contains NAs > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On Wed, 25 Feb 2009, Rob Denniker wrote:> Dear list,> I have an irregular time series saved and exported as a zoo object. What > is the trick to force zoo to ignore the missing dates when reading it > back in? Thanks.Almost certainly there are no NAs in your index (although we can't say for sure as Gabor pointed out).> > write.zoo(g, file = "gdata.txt", index.name = "date", append = F, > quote = T, sep = ",")> > h <- read.zoo("gdata.txt", sep = ",", format = "Y-%m-%d")^^^ First problem: This should be %Y. Second problem: You need header = TRUE. Thus, I would guess that h <- read.zoo("gdata.txt", sep = ",", format = "%Y-%m-%d", header = TRUE) should do what you want. Z