[R] chron is.weekend() function
David James
dj at research.bell-labs.com
Fri Sep 7 16:44:07 CEST 2001
Hi Paul,
This is clearly a bug -- the argument needs to be coerced
to a "dates" class argument, since the underlying algorithm relies
on integer arithmetic (date+time objects are represented as
floating point numbers).
Thus you can use is.weekend(dates(mb.df$dtg)) as a workaround.
(I'll send you a fix later on).
Paul Hewson wrote:
> Hello,
>
> I have a dataset which has fields giving both calendar date and weekday. I
> know better functions are now available, but I am still using chron because
> of the is.holiday() function and a homemade (even Heath Robinson would be
> ashamed) is.daylight() function.
>
> As a check for typos in the data input, I checked that the dates matched the
> weekdays. I'm getting some confusing results from the is.weekend function
> in chron. For example (in US format: mm/dd/yy):
>
> > mb.df$dtg[is.weekend(mb.df$dtg) == FALSE & mb.df$Weekday == "Sun"]
> [1] (09/24/00 11:52:00) (07/30/00 13:30:00) (04/30/00 15:30:00)
> [4] (04/30/00 16:28:00) (06/04/00 17:35:00) (09/03/00 14:45:00)
> [7] (05/07/00 16:42:00) (12/17/00 11:55:00) (08/20/00 10:20:00)
> [10] (01/07/01 20:32:00) (06/18/00 15:45:00) (09/24/00 11:16:00)
> [13] (09/10/00 20:35:00) (03/18/00 17:50:00) (09/03/00 09:20:00)
> [16] (06/18/00 14:37:00) (09/24/00 15:47:00) (09/03/00 20:38:00)
>
> I have checked most of these dates on my calendar and it agrees with the
> original dataset that they are in fact Sundays. Also, I note that
> is.weekend() seems to think that Fridays from 2000 onwards are weekends.
>
> The dataset contains data from 1996 until early 2001 and chron's
> is.weekend() resolved dates correctly prior to 2000. From the command line
> however more recent dates are also resolved correctly. For example I
> tried:
>
> > is.weekend("09/02/01")
> [1] TRUE
>
> and
>
> > is.weekend("09/03/01")
> [1] FALSE
>
> which is correct and therefore gives me some worries about my data, but I
> would really appreciate any ideas as to where I should start looking.
>
> Thanks
>
> Paul
>
> This was run on R 1.3.0 on Mandrake 7.1 with chron 2.2-17
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> Paul Hewson tel. (01392) 382773
> Data Analyst and Research Officer
>
> Road Safety Team, Environment Directorate,
> Devon County Council,
> 1st Floor, Lucombe House,
> County Hall
> Topsham Road
> Exeter EX2 4QW
>
> tel (01392) 382773 fax (01392) 382135
> email phewson at devon.gov.uk
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
David A. James
Statistics Research, Room 2C-253 Phone: (908) 582-3082
Bell Labs, Lucent Technologies Fax: (908) 582-3340
Murray Hill, NJ 09794-0636
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list