It would be useful to have a parameter in the week()
function to set the initial day for the week. On the USA is common to consider as a starting day for a week Sunday, whereas in Europe we start the week on Monday.
I would also like to see this feature and suggest it be made for all relevant functions. I just came across this myself when using wday
. Are there others? I thought it came back as a character string, but it comes back as a factor starting on Sunday (I changed the documentation to reflect it is a factor not a string). But I would prefer the factoring to start on Monday.
It is probably easiest if you make it general to take a first_day_of_week
argument that defaults to "Sunday"
.
In addition to being useful with week
, an argument to wday
to set the start of the week to Monday makes sense in the context of the isoxxx
functions (isoweek
and now isoyear
). People often want day number of the wday
of the iso week, which always starts on a monday. (for example 2013-53-1 to 2015-53-7.
Happy to work on this if it sounds like a good idea.
Happy to work on this if it sounds like a good idea.
I think it would be very useful. We just have to check that all lubridate code doesn't explicitly rely on the first day being Sunday. If it were after me I would even change the default to Monday as that's how iso defines it.
This would be a very useful feature. Just to emphasise the point: I would especially like to have this enabled floor_date when executed with unit="week". Maybe introduce a unit "isoweek" or an option for global application to all releant lubridate functions in a session.
Just to chime in, I'd like this too. When needed one can rearrange wday levels with something like this
s$day_name <- factor(s$day_name, levels = c("Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"))
but a general option would be nice.
Also, would it make sense to take week start based on the locale LC_TIME
value of the machine (Sys.getlocale()
). I am not sure if this is cross platform compatible though.
Also this has been a feature request for two years now... no takers?
I am not a big fan of locale-dependent settings as the same code will produce different results for different people. But given that in this regard to core R and some parts in lubridate (locale dependent parsing) are already locale dependent it might make sense to have week start locale dependent as well. But I am afraid this would break backward compatibility quite badly.
One problem I have with locale-dependent settings is that I do work for customers in multiple locales. So sometimes I deliver output that has the first day Sunday, other times Monday. And that does not depend on my locale, but my customers'. Instead maybe something that could be in options
that you could have in your .Rprofile would be better.
I'm currently using floor_date() extensively for a project and happen to need it to collapse on Saturday which is obviously not typical but would be nice to have the option to do. Something like floor_date(data$date, weekstart = 'Saturday')
You can do this with floor_date(x, "week") - days(1)
.
That doesn't change the actual week, just how its labeled. To actually shift the window I use
floor_date( x + days(1), "week") - days(1)
Hello everybody, I am also interested in this feature. In many asset pricing studies, one can use different week-cycles (say Monday to Monday, or Friday to Friday, or even Wed to Wed). It would be nice to have that directly in lubridate
. What do you think?
See here for other people struggling with that https://stackoverflow.com/questions/40554231/dplyr-how-to-aggregate-a-dataframe-by-week?noredirect=1#40554306
One can always code it manually, but I think lubridate
should probably handle that out-of-the-box to be the must-have package in date-management 馃挴
Given that the round-functions are gaining a week_start
argument, should the argument to determine the start of the week not also be week_start
instead of start
for wday()
?
This is a good point. Thanks for pointing it out. I made this change. Hesitated a bit because start
was introduced already 6 months ago, but given that back then it was the same development version I went with the consistency on this one.
Most helpful comment
This would be a very useful feature. Just to emphasise the point: I would especially like to have this enabled floor_date when executed with unit="week". Maybe introduce a unit "isoweek" or an option for global application to all releant lubridate functions in a session.