[R] Working with Date
Ista Zahn
istazahn at gmail.com
Tue Dec 31 23:37:06 CET 2013
Use, format() to extract a character string representation of the
year, then paste() it together with Months. Like this:
paste(Months, format(Given_Date, format = "%Y"), sep = "-")
See ?strftime for details.
Best,
Ista
On Tue, Dec 31, 2013 at 4:53 PM, Christofer Bogaso
<bogaso.christofer at gmail.com> wrote:
> Hi again,
>
> Happy new year 2014 to every R gurus and users.
>
> I am struggling with some calculation with dates... Let say I have
> following vector of months:
>
> Months <- c("Jan", "Dec", "Mar")
>
> Now I need to assign year with them. This assignment will be based on some
> given date. Let say my given date is :
>
> Given_Date <- as.Date("2013-12-23")
>
> So in this case, the modified month will be:
>
> Months_Mod <- c("Jan-2014", "Dec-2013", "Mar-2014")
>
> However if given date is:
>
> Given_Date <- as.Date("2014-01-04")
>
> then the modified months will be:
>
> Months_Mod <- c("Jan-2014", "Dec-2014", "Mar-2014")
>
> My problem is that, I can not extablish some logic around it, so that I can
> do it programmatically for any Month-vector and for any Given-date.
>
> Can someone help me to accomplice this?
>
> Thank for your help
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list