[R] counting weekday in a month in R
Nordlund, Dan (DSHS/RDA)
NordlDJ at dshs.wa.gov
Thu Dec 13 22:38:49 CET 2007
> -----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
More information about the R-help
mailing list