[R] Find out the day of week for a chron object?

Gabor Grothendieck ggrothendieck at myway.com
Wed Mar 3 12:58:02 CET 2004


Here are three different ways (using x as defined in your 
post):

 with( month.day.year(x), day.of.week(month,day,year) )

 do.call( "day.of.week", month.day.year(x) )

 as.numeric(x-3)%%7   # uses fact that chron(3) is Sunday

---
Date:   Mon, 1 Mar 2004 22:18:33 +0530 
From:   Ajay Shah <ajayshah at mayin.org>
To:   r-help <r-help at stat.math.ethz.ch> 
Subject:   [R] Find out the day of week for a chron object? 

 
I know that this is correct:

library(chron)
x = dates("01-03-04", format="d-m-y", out.format="day mon year")
print(x)

It gives me the string "01 Mar 2004" which is correct.


I also know that I can say:

print(day.of.week(3,1,2004))

in which case he says 1, for today is monday.


My question is: How do I combine these two!? :-) I have a data file
which is being parsed nicely and read in using the chron() function. I
need to identify fridays and treat them differently. So I need to run
the day.of.week function. But day.of.week() doesn't eat a chron
object, he insists he wants m,d,y. This seems quite odd. Any idea what
I can do?

Thanks,

-ans.

-- 
Ajay Shah Consultant
ajayshah at mayin.org Department of Economic Affairs
http://www.mayin.org/ajayshah Ministry of Finance, New Delhi




More information about the R-help mailing list