Complete month name from as.yearmon()

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

Complete month name from as.yearmon()

Bogaso
Hi,

I am wondering if there is any way to get the full name from as.yearmon()
function. Please consider below example:

library(quantmod)
as.yearmon(Sys.Date())

This gives: [1] "Apr 2019".

How can I extract the full name ie. 'April 2019'

Appreciate your pointer. Thanks,

        [[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: Complete month name from as.yearmon()

Achim Zeileis-4
On Sat, 13 Apr 2019, Christofer Bogaso wrote:

> Hi,
>
> I am wondering if there is any way to get the full name from as.yearmon()
> function. Please consider below example:
>
> library(quantmod)
> as.yearmon(Sys.Date())
>
> This gives: [1] "Apr 2019".
>
> How can I extract the full name ie. 'April 2019'

Internally, printing/formatting of yearmon objects uses the format method
for Date objects, see ?format.Date. The default is "%b %Y" where %b is the
abbreviated month name in the current locale. %B gives you the full month
name, both for Date directly and for yearmon:

R> format(Sys.Date(), "%B %Y")
[1] "April 2019"
R> format(as.yearmon(Sys.Date()), "%B %Y")
[1] "April 2019"


> Appreciate your pointer. Thanks,
>
> [[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.
>

______________________________________________
[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: Complete month name from as.yearmon()

Enrico Schumann-2
In reply to this post by Bogaso
>>>>> "CB" == Christofer Bogaso <[hidden email]> writes:

    CB> Hi,
    CB> I am wondering if there is any way to get the full name from as.yearmon()
    CB> function. Please consider below example:

    CB> library(quantmod)
    CB> as.yearmon(Sys.Date())

    CB> This gives: [1] "Apr 2019".

    CB> How can I extract the full name ie. 'April 2019'

    CB> Appreciate your pointer. Thanks,


library("zoo")   ## where 'as.yearmon' comes from
format(as.yearmon(Sys.Date()), "%B %Y")
## [1] "April 2019"

Note that this will give you the full monthname in your
locale.


--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

______________________________________________
[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.