Re: [R] counting weekday in a month in R

From: Nordlund, Dan (DSHS/RDA) <NordlDJ_at_dshs.wa.gov>
Date: Thu, 13 Dec 2007 13:38:49 -0800

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of tom soyer
> Sent: Thursday, December 13, 2007 1:27 PM
> To: r-help_at_r-project.org
> Subject: [R] counting weekday in a month in R
>
> Hi,
>
> I am trying to count weekday of the month using R. For
> example, 1/4/2001
> is the 4th weekday of Jan, and 1/5/2001 is the 5th weekday of
> the month, and
> 1/8/2001 is the 6th weekday of the month, etc. I get as far
> as extracting
> the weekdays from a sequence of dates (see below). But I have not yet
> figured out a fast way of counting without using a For Loop.
> Does anyone
> know how to do such counting efficiently in R?
>
> Thanks!
>
> library(chron)
> dts=seq(dates("1/4/01"),dates("3/31/01"),1)
> wkday=dts[!is.weekend(dts)]
> weekdays(wkday)
> [1] Thu Fri Mon Tue Wed Thu Fri Mon Tue Wed Thu Fri Mon Tue
> Wed Thu Fri Mon
> Tue Wed
> [21] Thu Fri Mon Tue Wed Thu Fri Mon Tue Wed Thu Fri Mon Tue
> Wed Thu Fri Mon
> Tue Wed
> [41] Thu Fri Mon Tue Wed Thu Fri Mon Tue Wed Thu Fri Mon Tue
> Wed Thu Fri Mon
> Tue Wed
> [61] Thu Fri
> Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
>
>
>
> --
> Tom

How about length(wkday) ?

Hope this is helpful,

Dan

Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services Olympia, WA 98504-5204    



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. Received on Thu 13 Dec 2007 - 21:43:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 13 Dec 2007 - 22:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.