Re: [R] adding 1 month to a date

From: David Forrest <drf5n_at_maplepark.com>
Date: Thu 13 Oct 2005 - 02:50:22 EST

On Wed, 12 Oct 2005, Jim Porzak wrote:

> OTOH,
>
> > seq(as.Date("2004-01-31"), by = "month", length = 14)
> [1] "2004-01-31" "2004-03-02" "2004-03-31" "2004-05-01" "2004-05-31"
> [6] "2004-07-01" "2004-07-31" "2004-08-31" "2004-10-01" "2004-10-31"
> [11] "2004-12-01" "2004-12-31" "2005-01-31" "2005-03-03"
>
> I would prefer to see dates forced to be within each month, not
> "leaking" into next month.
>
> IOW:
> [1] "2004-01-31" "2004-02-29" "2004-03-31" "2004-04-30" "2004-05-31", etc

It depends how you intend "1 month after 2004-01-31". Is the the same number of days before the beginning of the next month or after the end of the stated month?

   seq(as.Date("2004-02-01"), by = "month", length = 14)-1

   [1] "2004-01-31" "2004-02-29" "2004-03-31" "2004-04-30" "2004-05-31"

Dave

-- 
 Dr. David Forrest
 drf@vims.edu                                    (804)684-7900w
 drf5n@maplepark.com                             (804)642-0662h
                                   http://maplepark.com/~drf5n/

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Oct 13 02:56:07 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:48:49 EST