Skip to content

Instantly share code, notes, and snippets.

@tony91782
Created May 1, 2011 19:51
Show Gist options
  • Save tony91782/950802 to your computer and use it in GitHub Desktop.
Save tony91782/950802 to your computer and use it in GitHub Desktop.
## --------------------------- ##
## Function takes a vector of ##
## dates as its input. ##
## ##
## It produces a vector of ##
## dates that are the first ##
## in their respective months ##
## --------------------------- ##
firstDayMonth=function(x)
{
x=as.Date(as.character(x))
day = format(x,format="%d")
monthYr = format(x,format="%Y-%m")
y = tapply(day,monthYr, min)
first=as.Date(paste(row.names(y),y,sep="-"))
as.factor(first)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment