From ripley at stats.ox.ac.uk  Mon Dec 14 10:14:19 2009
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 14 Dec 2009 09:14:19 +0000 (GMT)
Subject: [Rd] Calendar week ISO (PR#14132)
In-Reply-To: <20091211212513.73E592833EE0@mail.pubhealth.ku.dk>
References: <20091211212513.73E592833EE0@mail.pubhealth.ku.dk>
Message-ID: <alpine.OSX.1.00.0912131234110.259@tystie.local>

Why are you reporting a POSIX standard feature missing in your OS as a 
bug in R?  (One that is even documented on the help page.)

On more comprehensive OSes you can use the %V format of strftime. 
You could compile a replacement for Windows' strftime and link it into 
your build of R, as we have done for so many other Windows lacunae.
Then in your example use as.integer(strftime(tmp.d, "%V"))

On Fri, 11 Dec 2009, samandrew at gmx.ch wrote:

> Hi there
>
> =20
>
> I use Gnu R sometimes at work.=20
>
> =20
>
> Unfortunately we use Windows and R has problems with getting the calendar

That is simply false: R is not responsible for the lack of standards 
compliance of Windows, and filing a bug report with Microsoft would be 
much more appropriate.

> week number with the first week as the one which has at least 4 days. A
> colleague told me that he has the same problem.=20
>
> =20
>
> Below you can see what I use now, for finding the right week.=20
>
> =20
>
> =20
>
> Kind regards,=20
>
> Samuel Andreas Meichtry
>
> =20
>
> =20
>
> #Excel-Funktion
>
> #=3DK=DCRZEN((A3-DATUM(JAHR(A3+3-REST(A3-2;7));1;REST(A3-2;7)-9))/7)
>
> =20
>
> =20
>
> #R-Funktion
>
> KW<-function(x){=20=20=20=20
>
>    return(floor(
>
>    as.numeric((x-(as.Date(ISOdate(
>
> =20
> as.numeric(format(as.Date(as.numeric(x)+3+25569-2-(as.numeric(x)-2+25569)%%7
> ,origin=3D"1900-01-01"),"%Y")),1,1)
>
>    )+((as.numeric(x)-2+25569)%%7-9)-1))/7)))=20=20=20=20=20=20=20=20=20=20=
> =20=20=20=20=20=20
>
> }
>
> =20
>
> tmp.d <- seq(as.Date("1970-01-01"),as.Date("2009-01-01"),"days")
>
> df<-data.frame(TimeStamp=3Dtmp.d,KW=3DKW(tmp.d))
>
> =20
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] Calendar week ISO (PR#14132)
Prof Brian Ripley