I didn't mean to say xts was always an option with zoo - that was only with regard to converting back and forth to get access to the subset feature of xts. If you really need zooreg, you're better off staying with zooreg.
Jeff On Fri, Mar 4, 2011 at 9:19 AM, Jeffrey Ryan <[email protected]>wrote: > This will work with xts in case that is an option (always is, since zoo and > xts share the same basic structure) > > library(xts) > x <- xts(rnorm(60), as.Date("2011-01-01")+0:59)[-2] > > x[as.Date(c("2011-01-01", "2011-01-02", "2011-01-03"))] <- NA > head(x) > [,1] > 2011-01-01 NA > 2011-01-03 NA > 2011-01-04 0.1433278 > 2011-01-05 -0.3239116 > 2011-01-06 0.5226191 > 2011-01-07 -1.1774623 > > Slightly different semantics, but this will do what you want assuming the > dates you are selecting are a range: > > x <- xts(rnorm(60), as.Date("2011-01-01")+0:59)[-2] > x['2011-01-01/2011-01-03'] <- NA > head(x) > [,1] > 2011-01-01 NA > 2011-01-03 NA > 2011-01-04 1.2909828095 > 2011-01-05 -0.0000222576 > 2011-01-06 0.4758526846 > 2011-01-07 -1.1725908376 > > > > > Best, > Jeff > > > On Fri, Mar 4, 2011 at 5:10 AM, Bogaso <[email protected]>wrote: > >> Hi all, I having some problem in replacing some observation of a zoo >> object >> with NA. Here I have tries followings: >> >> > MyData <- zooreg(rnorm(60), start=as.Date("2011-01-01"))[-2] >> > MyData[as.Date(c("2011-01-01", "2011-01-02", "2011-01-03"))] <- NA ## I >> > like to replace values with those indices with 'NA' >> > MyData >> Error in dimnames(x) <- dn : >> length of 'dimnames' [1] not equal to array extent >> >> Can somebody point me on the correct approach? >> >> Thanks, >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Replacing-some-observation-of-a-zoo-object-tp3335062p3335062.html >> Sent from the Rmetrics mailing list archive at Nabble.com. >> >> _______________________________________________ >> [email protected] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-sig-finance >> -- Subscriber-posting only. If you want to post, subscribe first. >> -- Also note that this is not the r-help list where general R questions >> should go. >> > > > > -- > Jeffrey Ryan > [email protected] > > www.lemnica.com > > -- Jeffrey Ryan [email protected] www.lemnica.com [[alternative HTML version deleted]] _______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
