[R] year and week to date - before 1/1 and after 12/31

peter salzman peter@@@lzm@nu@er @ending from gm@il@com
Tue Oct 16 16:22:44 CEST 2018


hi,

to turn year and week into the date one can do the following:

as.Date('2018 05 Sun', "%Y %W %a")

however, when we want the Sunday (1st day of week) of the 1st week of 2018
we get NA because 1/1/2018 was on Monday

as.Date('2018 00 Mon',format="%Y %U %a")
## 2018-01-01
as.Date('2018 00 Sun',format="%Y %U %a")
## NA

btw the same goes for last week
as.Date('2017 53 Sun',format="%Y %U %a")
## 2017-12-31
as.Date('2017 53 Mon',format="%Y %U %a")
## NA

So my question is :
how do i get
from "2018 00 Sun" to 2018-12-31
and
from "2017 53 Mon" to 2018-01-01

i realize i can loop over days of week and do some if/then statements,
but is there a built in function?

thank you
peter





-- 
Peter Salzman, PhD
Department of Biostatistics and Computational Biology
University of Rochester

	[[alternative HTML version deleted]]



More information about the R-help mailing list