[R] converting numbers in "YYYYMM" format to last calendar day and last exchange trading day of the month

Gabor Grothendieck ggrothendieck at gmail.com
Fri Sep 28 09:42:22 CEST 2007


Using as.yearmon and as.Date.yearmon with frac=1 (both from
the zoo package), the last calendar day of the month is:

	library(zoo)
	d <- c("200701", "200702")

	lastday <- as.Date(as.yearmon(d, "%Y%m"), frac = 1)

and the zoo quickref

                vignette("zoo-quickref")

has a nextfri function that you can modify to be lastfri.  See
the help desk article in R News 4/1 for more on dates and times.

Now make a vector of holidays, h, and for each last friday
decrement it by 1 until its no longer in h.


On 9/27/07, Thomas Pujol <thomas.pujol at yahoo.com> wrote:
>    I have a vector that contains month and year in the format YYYYMM (e.g."200701", "200702")
>
>  I wish to do to things:
> 1. I need      to convert to a date that is the last calendar day of each month.
>
> 2. I need      to convert this to a date that is the last U.S. stock-exchange trading day      of each month.
>            Any advice is appreciated,
>  mymonths <- c(200701, 200702)
>
> ---------------------------------
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>



More information about the R-help mailing list