D'Oh -- just spotted it (don't know what was wrong with me): in your code: "2011-01-05" and ts = zoo(x dt) need to be changed.
If you do that, the same trick time(ts)[ts==3] will work. Still, I'm a big xts fan. Michael On Tue, Aug 9, 2011 at 10:45 PM, R. Michael Weylandt < michael.weyla...@gmail.com> wrote: > I'd suggest you look into the xts class and write > > require(xts) > xts = as.xts(1:5,Sys.Date()+1:5) > time(xts)[xts==3] > > By the way, your code isn't pastable for me: not sure why. > > Michael Weylandt > > > On Tue, Aug 9, 2011 at 10:39 PM, Richard Ma <xuanlong...@uts.edu.au>wrote: > >> Hi all, >> >> I have a zoo time series object, see below code: >> >> ------------------------------------------------------------------------------------------- >> >> # This is a pasteable example >> library(zoo) >> >> x <- c(1, 2, 3, 4, 5) >> dt <- c("2011-01-01", "2011-01-02", "2011-01-03", "2011-01-04", >> "201-01-05") >> ts <- zoo(x, ts) >> >> >> ------------------------------------------------------------------------------------------- >> >> Now, I want to know the date when 'ts' equal to a specific value. In this >> example, suppose I want to know when the ts = 3? The program should return >> "2011-01-03". >> >> Is there a function to do this job conveniently? >> >> Regards, >> Richard >> >> ----- >> Richard Ma >> PhD student, Ecology & Remote Sensing >> Climate Change Cluster, Department of Environment Science >> University of Technology, Sydney >> http://everydropr.wordpress.com >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/How-to-get-the-date-of-specific-value-within-a-zoo-object-tp3731885p3731885.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help@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. >> > > [[alternative HTML version deleted]] ______________________________________________ R-help@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.