On Sat, Mar 9, 2013 at 11:41 AM, Christofer Bogaso <
bogaso.christofer@gmail.com> wrote:

> Hello again,
>
> Let say I have an non-negative integer vector (which may be random):
>
> Vec <- c(0, 13, 10, 4)
>
> And I have a date:
>
> > Date <- as.Date(Sys.time())
> > Date
> [1] "2013-03-09"
>
>
>
> Using these 2 information, I want to get following date-vector:
>
> New_Vec <- c("2013-03-01", "2014-04-01", "2014-01-01", "2013-07-01")
>
> Basically the month-difference between 'New_Vec' and 'Date' will be 'Vec '
>
> Is there any R function to do it programmatically?
>
>
Do you always want the first day of the month? If so, I think

library(zoo)
?yearmon

is what you are looking for. Specifically: convert to yearmon, add in the
month difference, convert back to date to get the first day of the month.

Cheers,

MW


>
> Thanks for your help.
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]

