[R] Count number of Fridays in a month

2014-10-10 Thread Abhinaba Roy
Hi R helpers, I want to write a function which will 1. Count the number of fridays in the current month ( to extract month from given date) and also the number of fridays in the preceeding month 2. Calculate the ratio of the number of fridays in current month to the number of fridays in the

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Duncan Murdoch
On 10/10/2014, 7:28 AM, Abhinaba Roy wrote: Hi R helpers, I want to write a function which will 1. Count the number of fridays in the current month ( to extract month from given date) and also the number of fridays in the preceeding month 2. Calculate the ratio of the number of fridays

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Abhinaba Roy
Hi Duncan, I have converted the string to a POSIXIt object using strptime('31-may-2014',format=%d-%b-%Y) But could not figure out the way forward. Could you please elaborate a bit? On Fri, Oct 10, 2014 at 5:14 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/10/2014, 7:28 AM,

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Duncan Murdoch
On 10/10/2014 8:10 AM, Abhinaba Roy wrote: Hi Duncan, I have converted the string to a POSIXIt object using strptime('31-may-2014',format=%d-%b-%Y) But could not figure out the way forward. Could you please elaborate a bit? Try this: ?POSIXlt Duncan Murdoch On Fri, Oct 10, 2014 at

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Barry Rowlingson
Or try this: fridays - function(the_day){ require(lubridate) day(the_day) = 1 the_month = seq(the_day, the_day+months(1)-days(1),1) sum(wday(the_month) == 6) } That returns the number of Fridays in the month of a Date object given as arg: fridays(as.Date(2012-01-01)) [1] 4

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Gabor Grothendieck
On Fri, Oct 10, 2014 at 7:28 AM, Abhinaba Roy abhinabaro...@gmail.com wrote: Hi R helpers, I want to write a function which will 1. Count the number of fridays in the current month ( to extract month from given date) and also the number of fridays in the preceeding month 2. Calculate the

Re: [R] Count number of Fridays in a month

2014-10-10 Thread PO SU
In my Impression, there seems  exsits a function (let just call weekday) which can return a POSIXlt format date 's weekday. That means,  weekday( 31-may-2014 ) may return the right weekday maybe 5, so  a clumsy method is start to judge from 1-may-2014 to 31-may-2014 , you get  a vector x,