Ogre Magi Ogre Magi - 9 months ago 41
R Question

Opposite of timeNthNdayInMonth

Trying to find a function which can take a date and tell me which day it is,

e.g. if I input today's date, which is "12/29/2014", it will say "it is the 5th Monday of the month" (but doesn't have to be a string output, it can be 5,1 as output representing 5th Mon). It is kinda the opposite of timeNthNdayInMonth in timeDate library which tells you the date given nth nday.

Answer Source

Here's a function f():

f <- function(date) 
  paste(ceiling(as.numeric(format(date, "%d")) / 7), format(date, "%w"), sep = ",")