[R] how many 7th of the month is there between two dates

Gabor Grothendieck ggrothendieck at myway.com
Tue Feb 15 18:16:40 CET 2005


Omar Lakkis <uofiowa <at> gmail.com> writes:


: I want to caculate how many an exact day of the month there is between
: two dates.
: 
: For example; How many 7th of the month is there between "1998/12/17"
: and "2000/1/7". To make the problem simple, the day of the month (7)
: is the day in the 2nd date.

d1 <- as.Date("1998/12/17")
d2 <- as.Date("2000/1/7")

day <- function(x) as.numeric(format(x, "%d"))

sum(day(seq(from = d1, to = d2, by = "day")) == day(d2))




More information about the R-help mailing list