Truncating dates (and other date-time manipulations)
One last item that could be of use: ?timeBasedSeq Lets you create ranges in any standard format, with simple ISO style formatting. The level of detail you specify is interpreted as the resolution that is desired. e.g.
timeBasedSeq(2000/2008)
[1] "2000-01-01" "2001-01-01" "2002-01-01" "2003-01-01" "2004-01-01" [6] "2005-01-01" "2006-01-01" "2007-01-01" "2008-01-01"
timeBasedSeq(2000/200012)
[1] "Jan 2000" "Feb 2000" "Mar 2000" "Apr 2000" "May 2000" "Jun 2000" [7] "Jul 2000" "Aug 2000" "Sep 2000" "Oct 2000" "Nov 2000" "Dec 2000"
timeBasedSeq(2000/200012, 'Date')
[1] "2000-01-01" "2000-02-01" "2000-03-01" "2000-04-01" "2000-05-01" [6] "2000-06-01" "2000-07-01" "2000-08-01" "2000-09-01" "2000-10-01" [11] "2000-11-01" "2000-12-01"
timeBasedSeq(2000/20000115)
[1] "2000-01-01" "2000-01-02" "2000-01-03" "2000-01-04" "2000-01-05" [6] "2000-01-06" "2000-01-07" "2000-01-08" "2000-01-09" "2000-01-10" [11] "2000-01-11" "2000-01-12" "2000-01-13" "2000-01-14" "2000-01-15"
timeBasedSeq(2000/2000010110)
[1] "2000-01-01 00:00:00 CST" "2000-01-01 01:00:00 CST" [3] "2000-01-01 02:00:00 CST" "2000-01-01 03:00:00 CST" [5] "2000-01-01 04:00:00 CST" "2000-01-01 05:00:00 CST" [7] "2000-01-01 06:00:00 CST" "2000-01-01 07:00:00 CST" [9] "2000-01-01 08:00:00 CST" "2000-01-01 09:00:00 CST" [11] "2000-01-01 10:00:00 CST"
Jeff Ryan 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. 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. Some examples are at: http://www.quantmod.com http://www.quantmod.com My presentation slides from July's Rmetrics conference in Switzerland are posted here: http://www.quantmod.com/Rmetrics2008/ http://www.quantmod.com/Rmetrics2008/ 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 Jeff
View this message in context: http://www.nabble.com/Truncating-dates-%28and-other-date-time-manipulations%29-tp19436962p19458976.html Sent from the R help mailing list archive at Nabble.com.