Re: [R] Incrementing Dates

From: Dirk Eddelbuettel <edd_at_debian.org>
Date: Wed, 23 Apr 2008 00:32:18 +0000

On Wed, Apr 23, 2008 at 12:17:55PM +1200, Worik R wrote:
> How can I increment the value of a Date class?
>
> I want to add a day, month or year to a date.

As the shoe company from Portland would say, "just do it". The key is knowing that the seq() function has a variant operating on the Date class:

> today <- Sys.Date()
> today
[1] "2008-04-22"
> args(seq.Date)

function (from, to, by, length.out = NULL, along.with = NULL,

    ...)
NULL
> seq(today, by="month", length=1)

[1] "2008-04-22"
> seq(today, by="month", length=2)

[1] "2008-04-22" "2008-05-22"
> seq(today, by="week", length=2)

[1] "2008-04-22" "2008-04-29"
> seq(today, by="day", length=2)

[1] "2008-04-22" "2008-04-23"
>

Dirk

-- 
Three out of two people have difficulties with fractions.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 23 Apr 2008 - 00:44:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Apr 2008 - 01:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive