On Dec 20, 2010, at 10:58 AM, Luca Meyer wrote:

Right, I appreciate the first day of the year start date. I am just wondering why then the cut off day is not the same for the rest of the year...but it's all right to use other packages.

Are you saying it shifts within the year? I am not seeing that:

require(lubridate)

> weekdays(as.POSIXct("2010-01-01")+(0:8)*24*60*60)
[1] "Friday" "Saturday" "Sunday" "Monday" "Tuesday" "Wednesday"
[7] "Thursday"  "Friday"    "Saturday"
> week(as.POSIXct("2010-01-01")+(0:8)*24*60*60)
[1] 1 1 1 1 1 1 2 2 2

Looks to be incrementing weeks between Wed and Thurs at the beginning of the year just as it did in your example. I admit that I thought that it should be shifting at the Thursday - Friday divide, but setting a zero point can be ambiguous. I thought if it were Midnight Thursday-Friday that all of Thurdays would be in week 1. But at least it appears consistent.


Thanks,
Luca

Il giorno 20/dic/2010, alle ore 14.16, David Winsemius ha scritto:


On Dec 20, 2010, at 12:54 AM, Luca Meyer wrote:

All right, I get it now: lubridate's week() define weeks from Thursday till the following Wednesday. You'd probably agree with me that it's a bit strange what it is going to do over the turn of the year:

y <- as.POSIXct(c("2010-12-27","2010-12-28","2010-12-29","2010-12-30","2010-12-31","2011-01-01","2011-01-02","2011-01-03","2011-01-04","2011-01-05","2011-01-06","2011-01-07","2011-01-08","2011-01-09","2011-01-10","2011-01-11","2010-01-12","2010-01-13","2010-01-14"))
week(y)
[1] 52 52 52 53 53  1  1  1  1  1  1  2  2  2  2  2  2  2  3

Why would the first week of the year be made of 6 days and the turn from week 1 to week 2 on the night between Thursday and Friday and not Wednesday and Friday like every other week?

weeks in lubridate start on whatever day of the week is the first of that year.

If you want a Monday starting day (or the option to change to another starting day), then package chron has such facilities.



Cheers,
Luca



Il giorno 19/dic/2010, alle ore 18.14, Uwe Ligges ha scritto:



On 19.12.2010 13:20, David Winsemius wrote:

On Dec 19, 2010, at 5:11 AM, Luca Meyer wrote:

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

But 2010-12-15 is a Wednesday and 2010-12-16 is a Thursday.



Together with the description of ?week this shows that lubridate's week() function works as documented rather than as expected by Luca Meyer.

Uwe Ligges


David Winsemius, MD
West Hartford, CT



David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to