[R] Truncating dates (and other date-time manipulations)
Jeff Ryan
jeff.a.ryan at gmail.com
Fri Sep 12 18:25:34 CEST 2008
Not really the ceiling and floor, though I haven't tried your code
(and my brain isn't at 100% capacity today to simply parse the code in
my head :) )
Though I think ?firstof and ?lastof as well as startof/endof might be
something along those lines. ?to.period has the ability to change
periodicity of a series (price or OHLCV-style price). Internal to that
is a method to re-align the output series:
>From the help:
To adjust the final indexing style, it is possible to set
'indexAt' to one of the following: 'yearmon', 'yearqtr',
'firstof', 'lastof', 'startof', or 'endof'. The final index will
then be 'yearmon', 'yearqtr', the first time of the period, the
last time of the period, the starting time in the data for that
period, or the ending time in the data for that period,
respectively.
Might that be what you are after (not the actual implementation per
se, but the spirit).
BTW, I am philosophically opposed to typing :)
Actually the chartSeries stuff is quite dynamic (and no more
specialized IMO than boxplot et al) --- take a look.
Jeff
On Fri, Sep 12, 2008 at 11:16 AM, hadley wickham <h.wickham at gmail.com> wrote:
> On Fri, Sep 12, 2008 at 10:53 AM, Jeff Ryan <jeff.a.ryan at gmail.com> wrote:
>>
>> I'm still not entirely sure I follow the desired usage, as the original post
>> made no reference to ggplot2, but as Gabor mentioned the yearmon etc stuff
>> is quite useful.
>
> Well, I said "I need to be able to correct draw date-time scales",
> which means I need to be able to deal with a wide range of date time
> data types. I wasn't really aware of xts before - I'll definitely
> look into it in more detail.
>
>> If you are formatting arbitrary precision dates, take a look at
>> axTicksByTime in xts. Both xts and quantmod use it for plotting. The core
>> calculation is from ?endpoints
>>
>> I think the effect is what you desire --- though the logic of the function
>> may be more than you want/need. I use it within the package(s) to make
>> intelligent breaks given the periodicity of the data.
>
> That's exactly what I want! I've written my own method, but I think
> you've done a much nicer job. (Although I draw minor grid lines as
> well) I'll definitely look at using that function in a future version
> of ggplot2.
>
>>
>> Some examples are at: http://www.quantmod.com http://www.quantmod.com
>
> Very nice - however, I'm philosophically opposed to special purpose
> plotting functions!
>
>> Most of the functions you have written are somewhere within xts already. At
>> least the functionality is. See the vignette:
>> http://cran.r-project.org/web/packages/xts/index.html
>> http://cran.r-project.org/web/packages/xts/index.html
>
> Including the ceiling and floor functions? That's what I'm really
> interested in.
>
> Hadley
>
>
> --
> http://had.co.nz/
>
--
Jeffrey Ryan
jeffrey.ryan at insightalgo.com
ia: insight algorithmics
www.insightalgo.com
More information about the R-help
mailing list