[R] Convert week value to date

David Winsemius dwinsemius at comcast.net
Wed Aug 17 23:37:49 CEST 2011


On Aug 17, 2011, at 4:52 PM, Folkes, Michael wrote:

> Hello all,
> I'm hoping to convert a decimal value for week of the year back to a  
> date object.
> Eg:
> strptime(paste(2010,1:52,sep=" "),format="%Y %W")

Yeah, agree that seems as though it should have been successful. I  
cannot get any of my invocations using %W to work.

 > strptime(Sys.Date(), "%Y-%m-%d-%W")
[1] NA
 > strptime(Sys.Date(), "%Y-%m-%d")
[1] "2011-08-17"
 > strptime(Sys.Date(), "%Y-%m-%d %W")
[1] NA

Oh well.

seq.POSIXt(as.POSIXlt("2010-01-01"), by="week", length=52)

>
> I expected (hoped?) this would give me the date for Monday of each  
> week.  Instead, it's giving me 52 values of today's date.
>
> Where am I erring?
> Thanks
> Michael
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list