[R-SIG-Finance] select subset from xts time series object.

jeff.a.ryan at gmail.com jeff.a.ryan at gmail.com
Sat Apr 16 20:33:46 CEST 2011


xts on R-forge has something like this in adj.time, syntax is something like

adj.time(Sys.Date(), hour+2)

Still in progress. 

Hadley et al has a (silly name) package called lubridate (I personally can't say it without smirking). That will likely do what you want as well. Though syntax is peculiar IMO. 

Check the most recent JSS on that. 

Jeff
Jeffrey A. Ryan
jeff.a.ryan at gmail.com

-----Original Message-----
From: Noah Silverman <noah at smartmediacorp.com>
Sender: r-sig-finance-bounces at r-project.orgDate: Sat, 16 Apr 2011 10:48:34 
To: Joshua Ulrich<josh.m.ulrich at gmail.com>
Cc: R-SIG-Finance<r-sig-finance at stat.math.ethz.ch>
Subject: Re: [R-SIG-Finance] select subset from xts time series object.

Nice,

Thanks!

Next challenge:  Is there a package in R to do "date math".  (There is great stuff in other languages, so must be in R)

If I have a timetamp, It would be great to just "add 1 hour" or "add 7 minutes" and get back the proper date-time for it.

I'm looking at a lot of timeseries data this weekend and need to learn how to do some of this simple stuff in R to play with some ideas.

Thanks!

--
Noah Silverman
Smart Media Corp.
WebClipping.com
Tel: (323) 653-1900 x5207



On Apr 16, 2011, at 10:38 AM, Joshua Ulrich wrote:

> 
> On Apr 16, 2011 12:29 PM, "Noah Silverman" <noah at smartmediacorp.com> wrote:
> >
> > Perfect!
> >
> > I never thought about using a double colon.  Works quickly and cleanly.
> >
> > Now for the harder part.
> >
> > If I want to define my timestamps as variables first, how I can I subselect:
> >
> > a <- '2010-08-04 11:50:00'
> > b <- '2010-08-04 11:55:00'
> >
> >
> > ticks[a::b, ]   fails
> >
> Take a careful look ay what others have already suggested and what you're trying.  You're trying to apply a :: operator to two character vectors.
> 
> xts subsetting requires a single string, which you can create via paste(a, b, sep="::").
> 
> > Ideas?
> >
> > --
> > Noah Silverman
> > Smart Media Corp.
> > WebClipping.com
> > Tel: (323) 653-1900 x5207
> >
> >
> >
> > On Apr 16, 2011, at 10:12 AM, Hasan Diwan wrote:
> >
> > > On 16 April 2011 10:01, Noah Silverman <noah at smartmediacorp.com> wrote:
> > >> Hi,
> > >>
> > >> Thanks to Jeff Ryan's help, I was able to get my data into a nice XTS format.  I then followed his suggestion to use the make.index.unique() function to ensure that each tick had a slightly different time.  Everything looks great!
> > >>
> > >> Now, I want to select subsets of the data for short intervals - perhaps 5 minutes in size.
> > >>
> > >> For example, I want all the entries between:
> > >> 2010-08-04 11:50:00   and   2010-08-04 11:55:00
> > >>
> > >> I tried:      ticks[' 2010-08-04 11:50:00' :'2010-08-04 11:55:00' , ]    It failed
> > >> Then:      ticks[as.POSIXct(' 2010-08-04 11:50:00')  : asPOSIXct('2010-08-04 11:55:00' ), ]  Also fails
> > >
> > > ticks['2010-08-04 11:50:00::2011-08-04 11:55:00'] works brilliantly
> > > --
> > > Sent from my mobile device
> > > Envoyait de mon telephone mobil
> >
> > _______________________________________________
> > R-SIG-Finance at r-project.org 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.


	[[alternative HTML version deleted]]

_______________________________________________
R-SIG-Finance at r-project.org 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.


More information about the R-SIG-Finance mailing list