Without some data we can't tell precisely the setup but here it is using Date class and you can adapt it to your specific situation. We first define functions to get the prior wed (or the same day if its wed) and the last day of the prior month. Then we define the test data e of event dates and do the calculation.
library(zoo) # as.yearmon, as.Date.numeric prev.wed <- function(x) 7 * floor(as.numeric(x - 3 + 4)/7) + as.Date(3 - 4) prior.month.end <- function(x) as.Date(as.yearmon(x)) - 1 # test data e <- Sys.Date() + seq(0, length = 3, by = 100) as.numeric(e - prev.wed(prior.month.end(e))) * 24 * 60 On Wed, Aug 20, 2008 at 10:26 PM, M-J S Milloy <[EMAIL PROTECTED]> wrote: > > Hello, > > I have a dataset containing approx 1000 events spanning four years (2004.03 > to 2008.07). For each event, I'd like to determine the time (in minutes) > since the most recent final Wednesday of the month. I've found no obvious > solution on the list or online; I think I'll try to use functions in the > chron package. > > Anyone have any other advice? > > Thanks. > > > M-J > > > School of Population and Public Health, > University of British Columbia > Vancouver, Canada > > Centre for Excellence in HIV/AIDS, > St. Paul's Hospital > Vancouver, Canada > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.