Richard Ma
2011-Aug-10 02:39 UTC
[R] How to get the date of specific value within a zoo object?
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. Michael Weylandt
2011-Aug-10 02:45 UTC
[R] How to get the date of specific value within a zoo object?
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.ma@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]]
Seemingly Similar Threads
- Create a zoo/xts Time Series with Millisecond jumps
- Isn't aggreate.zoo supposed to work with POSIXct (zoo/TTR/xts issue)?
- How to do operations on zoo/xts objects with Monthly and Daily periodicities
- Strange zoo behaviour, possible bug?
- Time series: xts/zoo object at annual (yearly) frequency