I have a vector of dates.
I wish to find the month end date for each.
Any suggestions?
e.g.
For 12/15/05, I want 12/31/05,
For 10/15/1995, I want 10/31/1995, etc
__
[[alternative HTML version deleted]]
__
Here is one way using POSIX: (you can create a function to do this)
> x <- as.POSIXlt('2005-12-16') # a date
> x
[1] "2005-12-16"
> dput(x) #structure of the date
structure(list(sec = 0, min = 0, hour = 0, mday = 16, mon = 11,
year = 105, wday = 5, yday = 349, isdst = 0), .Names = c("sec",
"
Forgot you were asking for the end date, so just subtract a day:
> seq(x, by='month', length=2)[2] - 24*3600
[1] "2005-12-31 EST"
On 12/19/05, jim holtman <[EMAIL PROTECTED]> wrote:
>
> Here is one way using POSIX: (you can create a function to do this)
>
> > x <- as.POSIXlt('2005-12-16') # a
The zoo package has a yearmon class with as methods which can be
used:
library(zoo)
dd <- Sys.Date() # test data
as.Date(as.yearmon(dd), frac = 1)
as.yearmon converts the "Date" class date to a year and month of
class "yearmon" dropping the day and representing it internally in
a way consistent
endieck
Sent: Monday, December 19, 2005 11:59 AM
To: t c
Cc: r-help
Subject: Re: [R] given a mid-month date, get the month-end date
The zoo package has a yearmon class with as methods which can be
used:
library(zoo)
dd <- Sys.Date() # test data
as.Date(as.yearmon(dd), frac = 1)
as.yearmo
If you work much with time data and time series data and you have not
already mastered the "zoo" package, you may be interested in a small
testimonial from one unfamiliar with the names of Achim Zeileis and
Gabor Grothendieck two years ago: The package itself seems to have many
usefu