[R-SIG-Finance] question about time-stamp comparison?
R. Michael Weylandt
michael.weylandt at gmail.com
Fri Jan 20 17:44:11 CET 2012
I can't immediately come up with an counter-example where lexical
ordering and calendar ordering are different if you have a consistent
amount of digits, but wouldn't it just be easier (and more
computationally efficient) to convert your character to a POSIXct
before doing the comparison?
Or (if you actually read the xts documentation!) there's a (much) better trick:
? `[.xts`
tmp1["::20110920 12:01:33.386168"]
Michael Weylandt
On Fri, Jan 20, 2012 at 11:32 AM, Michael <comtech.usa at gmail.com> wrote:
> These are char strings:
> "2011-09-20 12:01:33.386168"
> In fact,
> I want to do subsetting of xts objects:
> lets say tmp1 is an xts object:
> tmp2 = tmp1[index(tmp1)< "2011-09-20 12:01:33.386168"]
> Will it work?
> Thanks again!
>
> On Fri, Jan 20, 2012 at 10:02 AM, Brian G. Peterson <brian at braverock.com>wrote:
>
>> On Fri, 2012-01-20 at 09:49 -0600, Michael wrote:
>> > Good morning all!
>> >
>> > Just wanted to confirm - how do I compare two date-time stamps in the
>> > following format?
>>
>> > > "2011-09-20 12:01:33.386168"< "2011-09-20 12:01:33.386169"
>> >
>> > [1] TRUE
>>
>> You don't tell us what class those timestamps are.
>>
>> Assuming you're using xts objects for your time series (which you should
>> be), then the index is POSIXct, and < > = , etc are defined for the
>> POSIXct class.
>>
>> It won't care about the string format.
>>
>> --
>> Brian G. Peterson
>> http://braverock.com/brian/
>> Ph: 773-459-4973
>> IM: bgpbraverock
>>
>>
>
> [[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