Created
May 1, 2011 19:51
-
-
Save tony91782/950802 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## --------------------------- ## | |
## 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