Re: [R] Processing dates and generating sequences of dates

2008-02-05 Thread Gavin Simpson
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO Dear Gabor and Jim, Many thanks for you solutions which all do what I wanted to achieve. Now I am spoilt for choice :-) All the best, G On Mon, 2008-02-04 at 22:38 -0500, Gabor Grothendieck wrote: > Here is another solution. It uses only R core > f

Re: [R] Processing dates and generating sequences of dates

2008-02-04 Thread Gabor Grothendieck
Here is another solution. It uses only R core functions. Note that as.Date(cut(x, "years")) gives Jan 1 of x's year where x is of class "Date": y <- as.Date(cut(range(my.dates), "years")) + c(0, 364) seq(y[1], y[2], "months") On Mon, Feb 4, 2008 at 1:00 PM, Gabor Grothendieck <[EMAIL PROTECTED]

Re: [R] Processing dates and generating sequences of dates

2008-02-04 Thread jim holtman
Does this do what you want? > your.dates <- c(as.Date('2005-05-21'), as.Date('2007-03-11')) > x.range <- as.numeric(format(range(your.dates),"%Y")) > x <- expand.grid(x.range[1]:x.range[2], 1:12) > x <- sort(sprintf("%d-%02d-01", x[,1], x[,2])) > > x [1] "2005-01-01" "2005-02-01" "2005-03-01" "20

Re: [R] Processing dates and generating sequences of dates

2008-02-04 Thread Gabor Grothendieck
OK. Here are two zoo solutions and one using only core functions. In the first dd is the first of the month of Jan and month of Dec of the first and last year respectively so we apply seq.Dates to that. In the second yr is Jan of the first and Jan of the last year as "yearmon" class and we adjust

Re: [R] Processing dates and generating sequences of dates

2008-02-04 Thread Gavin Simpson
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO On Mon, 2008-02-04 at 10:48 -0500, Gabor Grothendieck wrote: > Using zoo's yearmon class: > > library(zoo) > my.dates[!duplicated(as.yearmon(my.dates))] > > or, although you seem to disallow this in your question, > this would be an option: > > my.da

Re: [R] Processing dates and generating sequences of dates

2008-02-04 Thread Gavin Simpson
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO On Mon, 2008-02-04 at 10:48 -0500, Gabor Grothendieck wrote: > Using zoo's yearmon class: > > library(zoo) > my.dates[!duplicated(as.yearmon(my.dates))] > > or, although you seem to disallow this in your question, > this would be an option: > > my.da

Re: [R] Processing dates and generating sequences of dates

2008-02-04 Thread Gabor Grothendieck
Using zoo's yearmon class: library(zoo) my.dates[!duplicated(as.yearmon(my.dates))] or, although you seem to disallow this in your question, this would be an option: my.dates[!duplicated(format(my.dates, "%Y-%m"))] On Feb 4, 2008 10:39 AM, Gavin Simpson <[EMAIL PROTECTED]> wrote: > hits=-2.6 t

[R] Processing dates and generating sequences of dates

2008-02-04 Thread Gavin Simpson
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO Dear List, Say I have the following sequence of dates [*]: start <- as.Date("2005-01-05", format = "%Y-%d-%m") end <- as.Date("2007-10-07", format = "%Y-%d-%m") my.dates <- seq(start, end, by = "days") What I would like to generate is a sequence of d