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

Noah Silverman noah at smartmediacorp.com
Sat Apr 16 19:28:43 CEST 2011


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

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



More information about the R-SIG-Finance mailing list