Date operation Question in R

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Date operation Question in R

PaulJr
Hello everyone,

Is there a way to use the function seq to generate a date sequence in this
kind of format: jan-2007?

Also, is there a way to change the Sys.Date() format to the one mentioned
above (jan-2007)?

Thanks in advance for your valuable help,

Best regards,

Paul

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Date operation Question in R

Thomas Petzoldt-4
On 30.03.2017 23:34, Paul Bernal wrote:
> Hello everyone,
>
> Is there a way to use the function seq to generate a date sequence in
> this kind of format: jan-2007?

format(seq(ISOdate(2017,1,1), ISOdate(2017,12,31), "months"), "%b-%Y")

>
> Also, is there a way to change the Sys.Date() format to the one
> mentioned above (jan-2007)?

format(Sys.Date(), "%b-%Y")

see ?strptime for details.

Thomas

>
> Thanks in advance for your valuable help,
>
> Best regards,
>
> Paul

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Date operation Question in R

David Winsemius

> On Mar 30, 2017, at 3:16 PM, Thomas Petzoldt <[hidden email]> wrote:
>
> On 30.03.2017 23:34, Paul Bernal wrote:
>> Hello everyone,
>>
>> Is there a way to use the function seq to generate a date sequence in
>> this kind of format: jan-2007?
>
> format(seq(ISOdate(2017,1,1), ISOdate(2017,12,31), "months"), "%b-%Y")

But since the original one asked for a starting point of Sys.Date, on this 31st day of March, it might be useful to demonstrate that there are pifalls for the uninitiated useR. Note the many duplicate "months":

> format(seq(ISOdate(2017,1,31), ISOdate(2018,12,31), "months"), "%b-%Y")
 [1] "Jan-2017" "Mar-2017" "Mar-2017" "May-2017" "May-2017" "Jul-2017" "Jul-2017"
 [8] "Aug-2017" "Oct-2017" "Oct-2017" "Dec-2017" "Dec-2017" "Jan-2018" "Mar-2018"
[15] "Mar-2018" "May-2018" "May-2018" "Jul-2018" "Jul-2018" "Aug-2018" "Oct-2018"
[22] "Oct-2018" "Dec-2018" "Dec-2018"

--
David.

>
>>
>> Also, is there a way to change the Sys.Date() format to the one
>> mentioned above (jan-2007)?
>
> format(Sys.Date(), "%b-%Y")
>
> see ?strptime for details.
>
> Thomas
>
>>
>> Thanks in advance for your valuable help,
>>
>> Best regards,
>>
>> Paul
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.