[R] Alternative to extended recode sintax? Bug?

Luca Meyer lucam1968 at gmail.com
Sun Dec 19 11:11:09 CET 2010


Something goes wrong with the week function of the lubridate package:

> x= as.POSIXct(factor(c("2010-12-15 17:28:27",
+     "2010-12-15 17:32:34",
+     "2010-12-15 18:48:39",
+     "2010-12-15 19:25:00",
+     "2010-12-16 08:00:00",
+     "2010-12-16 08:25:49",
+     "2010-12-16 09:00:00")))
> require(lubridate)
> weekdays(x)
[1] "Mercoledì" "Mercoledì" "Mercoledì" "Mercoledì" "Giovedì"   "Giovedì"   "Giovedì"  
> week(x)
[1] 50 50 50 50 51 51 51
> 

Please notice Mercoledì=Wednesday and Giovedì=Thursday, why would the beginning of the week start on Thursday? Also please beware that on previous weeks this does not occur, that is all weeks till 49 will all begin on Mondays and end on Sundays as required.

Thanks,
Luca


Il giorno 18/dic/2010, alle ore 14.39, David Winsemius ha scritto:

> 
> On Dec 17, 2010, at 11:08 AM, Luca Meyer wrote:
> 
> x= factor(c("2009-03-30 00:00:00", "2009-04-06 00:00:00", "2009-04-13 00:00:00", "2009-04-20 00:00:00", "2009-04-27 00:00:00", "2009-05-04 00:00:00" ,"2009-05-11 00:00:00", "2009-05-18 00:00:00"))
> require(lubridate)
> xd=as.POSIXct(x)
> week(xd)
> # [1] 13 14 15 16 17 18 19 20
> year(xd)
> # [1] 2009 2009 2009 2009 2009 2009 2009 2009
> paste(year(xd), " W",week(xd), sep="")
> #[1] "2009 W13" "2009 W14" "2009 W15" "2009 W16" "2009 W17" "2009 W18" "2009 W19" "2009 W20"
> 
> 
> 
> David Winsemius, MD
> West Hartford, CT
> 



More information about the R-help mailing list