Weiyang Lim
2008-Sep-11 08:31 UTC
[R] How to obtain a sequence of dates consisting of only weekdays
Dear R-users, How do I obtain a sequence of dates consisting of only weekdays without the weekends in R? In S, I can do the following: timeSeq(from="12/17/2007", to="8/25/2008", by="weekdays") I tried using looking at timeSequence (fSeries package) and seq.Date (base package) but I do not know if I can specify "weekdays" rather than "day". Hope to have some assistance. Thank you! Regards, wy ********************************************************** The information provided in this e-mail is confidential and is for the sole use of the recipient. It may not be disclosed, copied or distributed in any form without the express permission of Henderson Global Investors and to the extent that it is passed on, care must be taken to ensure that this is in a form which accurately reflects the information presented here. Whilst Henderson Global Investors believe that the information is correct at the date of this e-mail, no warranty or representation is given to this effect and no responsibility can be accepted by Henderson Global Investors to any end users for any action taken on the basis of this information. Henderson Global Investors is the name under which Henderson Global Investors Limited (registered no. 906355), Henderson Fund Management plc (registered no. 2607112), Henderson Investment Funds Limited (registered no. 2678531), Henderson Investment Management Limited (registered no. 1795354) Henderson Alternative Investment Advisor Limited (registered no. 962757) and Henderson Equity Partners Limited (registered no.2606646) (each incorporated and registered in England and Wales with registered office at 4 Broadgate, London EC2M 2DA and authorised and regulated by the Financial Services Authority) provide investment products and services. Henderson Secretarial Services Limited (incorporated and registered in England and Wales, registered no. 1471624, registered office 4 Broadgate, London EC2M 2DA) is the name under which company secretarial services are provided. All these companies are wholly owned subsidiaries of Henderson Group plc (incorporated and registered in England and Wales, registered no. 2072534, registered office 4 Broadgate, London EC2M 2DA). We may record telephone calls or email for our mutual protection and to improve customer service. ********************************************************** [[alternative HTML version deleted]]
Yihui Xie
2008-Sep-11 09:02 UTC
[R] How to obtain a sequence of dates consisting of only weekdays
draw a subset of your data using a logical vector like this: # for 50 weeks rep(c(rep(TRUE, 5), rep(FALSE, 2)), 50) Yihui On Thu, Sep 11, 2008 at 4:31 PM, Weiyang Lim <Weiyang.Lim at henderson.com> wrote:> Dear R-users, > > How do I obtain a sequence of dates consisting of only weekdays without the weekends in R? > > In S, I can do the following: > > timeSeq(from="12/17/2007", to="8/25/2008", by="weekdays") > > I tried using looking at timeSequence (fSeries package) and seq.Date (base package) but I do not know if I can specify "weekdays" rather than "day". > > Hope to have some assistance. > > Thank you! > > Regards, > wy-- Yihui Xie <xieyihui at gmail.com> Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China
Yihui Xie
2008-Sep-11 09:23 UTC
[R] How to obtain a sequence of dates consisting of only weekdays
Then you can use c() to add the indices of those weeks which are not "complete", or use something like this # from Tuesday to next Wedsday> !(2:10 %% 7) %in% c(0,6)[1] TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE Yihui On Thu, Sep 11, 2008 at 5:08 PM, Weiyang Lim <Weiyang.Lim at henderson.com> wrote:> Hi, > > Thanks for the reply. I also thought of your method. But it will not be quite right if my starting day is not on a Monday. Then, it will include weekends? Hope to have flexibility in that the starting day can be any day of the week not just monday. > > wy >-- Yihui Xie <xieyihui at gmail.com> Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China
Yihui Xie
2008-Sep-11 09:42 UTC
[R] How to obtain a sequence of dates consisting of only weekdays
In fact, you can even use weekdays() to get the names of the weekdays and then use the operator "%in%" to exclude the weekends. In this case, I'm sure there will be no further problems :-) Yihui On Thu, Sep 11, 2008 at 5:33 PM, Weiyang Lim <Weiyang.Lim at henderson.com> wrote:> I see. That's a nice idea. Thanks. > > In that case, I suppose I will have to manually find out the starting weekday of the first day specified (I will have to know whether the starting day is Tuesday, Wednesday etc) before subsetting using what you have mentioned below. > > Thanks. > > Regards, > Weiyang >-- Yihui Xie <xieyihui at gmail.com> Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China
Gabor Grothendieck
2008-Sep-11 12:09 UTC
[R] How to obtain a sequence of dates consisting of only weekdays
See ?is.holiday in chron, e.g.
library(chron)
s <- seq(from = chron("12/17/2007"), to =
chron("8/25/2008"))
s.weekday <- s[!is.holiday(s)]
As discussed there one can also optionally define a .Holidays vector
containing dates which will also be excluded.
It also works with any class for which there is an as.chron
method. R News 4/1 discusses various date classes.
On Thu, Sep 11, 2008 at 4:31 AM, Weiyang Lim <Weiyang.Lim at
henderson.com> wrote:> Dear R-users,
>
> How do I obtain a sequence of dates consisting of only weekdays without the
weekends in R?
>
> In S, I can do the following:
>
> timeSeq(from="12/17/2007", to="8/25/2008",
by="weekdays")
>
> I tried using looking at timeSequence (fSeries package) and seq.Date (base
package) but I do not know if I can specify "weekdays" rather than
"day".
>
> Hope to have some assistance.
>
> Thank you!
>
> Regards,
> wy
>
> **********************************************************
>
> The information provided in this e-mail is confidential and is for the sole
use of the recipient. It may not be disclosed, copied or distributed in any form
without the express permission of Henderson Global Investors and to the extent
that it is passed on, care must be taken to ensure that this is in a form which
accurately reflects the information presented here.
>
> Whilst Henderson Global Investors believe that the information is correct
at the date of this e-mail, no warranty or representation is given to this
effect and no responsibility can be accepted by Henderson Global Investors to
any end users for any action taken on the basis of this information.
>
> Henderson Global Investors is the name under which Henderson Global
Investors Limited (registered no. 906355), Henderson Fund Management plc
(registered no. 2607112), Henderson Investment Funds Limited (registered no.
2678531), Henderson Investment Management Limited (registered no. 1795354)
Henderson Alternative Investment Advisor Limited (registered no. 962757) and
Henderson Equity Partners Limited (registered no.2606646) (each incorporated and
registered in England and Wales with registered office at 4 Broadgate, London
EC2M 2DA and authorised and regulated by the Financial Services Authority)
provide investment products and services. Henderson Secretarial Services
Limited (incorporated and registered in England and Wales, registered no.
1471624, registered office 4 Broadgate, London EC2M 2DA) is the name under which
company secretarial services are provided. All these companies are wholly owned
subsidiaries of Henderson Group plc (incorporated and registered in England !
> and Wales, registered no. 2072534, registered office 4 Broadgate, London
EC2M 2DA).
>
> We may record telephone calls or email for our mutual protection and to
improve customer service.
>
> **********************************************************
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
Weiyang Lim
2008-Sep-12 03:46 UTC
[R] How to obtain a sequence of dates consisting of only weekdays
This was precisely what I was looking for. I did not realize that chron package
allows for this.
Thank you very much, Gabor.
Many thanks also to Yihui for his kind assistance.
Best Regards,
Weiyang
-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com]
Sent: 11 September 2008 20:09
To: Weiyang Lim
Cc: r-help at r-project.org
Subject: Re: [R] How to obtain a sequence of dates consisting of only weekdays
See ?is.holiday in chron, e.g.
library(chron)
s <- seq(from = chron("12/17/2007"), to =
chron("8/25/2008"))
s.weekday <- s[!is.holiday(s)]
As discussed there one can also optionally define a .Holidays vector
containing dates which will also be excluded.
It also works with any class for which there is an as.chron
method. R News 4/1 discusses various date classes.
On Thu, Sep 11, 2008 at 4:31 AM, Weiyang Lim <Weiyang.Lim at
henderson.com> wrote:> Dear R-users,
>
> How do I obtain a sequence of dates consisting of only weekdays without the
weekends in R?
>
> In S, I can do the following:
>
> timeSeq(from="12/17/2007", to="8/25/2008",
by="weekdays")
>
> I tried using looking at timeSequence (fSeries package) and seq.Date (base
package) but I do not know if I can specify "weekdays" rather than
"day".
>
> Hope to have some assistance.
>
> Thank you!
>
> Regards,
> wy
>
> **********************************************************
>
> The information provided in this e-mail is confidential and is for the sole
use of the recipient. It may not be disclosed, copied or distributed in any form
without the express permission of Henderson Global Investors and to the extent
that it is passed on, care must be taken to ensure that this is in a form which
accurately reflects the information presented here.
>
> Whilst Henderson Global Investors believe that the information is correct
at the date of this e-mail, no warranty or representation is given to this
effect and no responsibility can be accepted by Henderson Global Investors to
any end users for any action taken on the basis of this information.
>
> Henderson Global Investors is the name under which Henderson Global
Investors Limited (registered no. 906355), Henderson Fund Management plc
(registered no. 2607112), Henderson Investment Funds Limited (registered no.
2678531), Henderson Investment Management Limited (registered no. 1795354)
Henderson Alternative Investment Advisor Limited (registered no. 962757) and
Henderson Equity Partners Limited (registered no.2606646) (each incorporated and
registered in England and Wales with registered office at 4 Broadgate, London
EC2M 2DA and authorised and regulated by the Financial Services Authority)
provide investment products and services. Henderson Secretarial Services
Limited (incorporated and registered in England and Wales, registered no.
1471624, registered office 4 Broadgate, London EC2M 2DA) is the name under which
company secretarial services are provided. All these companies are wholly owned
subsidiaries of Henderson Group plc (incorporated and registered in England !
> and Wales, registered no. 2072534, registered office 4 Broadgate, London
EC2M 2DA).
>
> We may record telephone calls or email for our mutual protection and to
improve customer service.
>
> **********************************************************
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
**********************************************************
The information provided in this e-mail is confidential and is for the sole use
of the recipient. It may not be disclosed, copied or distributed in any form
without the express permission of Henderson Global Investors and to the extent
that it is passed on, care must be taken to ensure that this is in a form which
accurately reflects the information presented here.
Whilst Henderson Global Investors believe that the information is correct at the
date of this e-mail, no warranty or representation is given to this effect and
no responsibility can be accepted by Henderson Global Investors to any end users
for any action taken on the basis of this information.
Henderson Global Investors is the name under which Henderson Global Investors
Limited (registered no. 906355), Henderson Fund Management plc (registered no.
2607112), Henderson Investment Funds Limited (registered no. 2678531), Henderson
Investment Management Limited (registered no. 1795354) Henderson Alternative
Investment Advisor Limited (registered no. 962757) and Henderson Equity Partners
Limited (registered no.2606646) (each incorporated and registered in England and
Wales with registered office at 4 Broadgate, London EC2M 2DA and authorised and
regulated by the Financial Services Authority) provide investment products and
services. Henderson Secretarial Services Limited (incorporated and registered
in England and Wales, registered no. 1471624, registered office 4 Broadgate,
London EC2M 2DA) is the name under which company secretarial services are
provided. All these companies are wholly owned subsidiaries of Henderson Group
plc (incorporated and registered in England and Wales, registered no. 2072534,
registered office 4 Broadgate, London EC2M 2DA).
We may record telephone calls or email for our mutual protection and to improve
customer service.