Uwe Ligges <ligges <at> statistik.uni-dortmund.de> writes:
> Matthew Dowle wrote:
> > 
> >>table(is.weekend(sapply(1:100, function(i){Sys.sleep(0.05);Sys.time()})))
> > 
> > FALSE  TRUE 
> >    68    32 
> 
> > It seems is.weekend() is unsure ?
> 
> It is completely sure, if an object is given is.weekend() knows about as in:
> 
> table(is.weekend(sapply(1:100, 
> function(i){Sys.sleep(0.05);as.chron(Sys.time())})))
> 
> (note the as.chron() call!)

Note that converting a POSIXct to chron using as.chron uses
the GMT datetime, not the datetime in your timezone.  So if its the
weekend in the GMT timezone but not in yours it will indicate that
its the weekend.  Similarly if its the weekend in your timezone
but not in the GMT timezone then it will indicate its not in the
weekend.

If you want the result relative to your timezone convert
to chron like this:

   now <- Sys.time()
   chron(unclass(as.Date(format(now))))

or even easier:

    chron(unclass(Sys.Date()))

Now apply is.weekend to that.

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to