I would like to change german month abbreviations like "Jan", "Feb", "Mär, "Apr", "Mai", and so on, to the full name of the months. Like "Januar", "Februar", "März", ...
I guess there is no such function available. For English abbreviations, there is the function month.abb
. Do you have an idea how I could do this not manually?
Thanks a lot
You can get full month name in the current locale with:
format(ISOdate(2000, 1:12, 1), "%B")
#months(ISOdate(2000, 1:12, 1)) #Alternative
and abbreviated month name in the current locale with:
format(ISOdate(2000, 1:12, 1), "%b")
#months(ISOdate(2000, 1:12, 1), TRUE) #Alternative
To change the locale have a look at How to change the locale of R? in case Sys.setlocale("LC_TIME", "de_DE.UTF-8")
is not working.
And to make the conversion local short to local long:
loc2loc <- setNames(format(ISOdate(2000, 1:12, 1), "%B"), format(ISOdate(2000, 1:12, 1), "%b"))
loc2loc["Jan"]
and local short to English long:
loc2eng <- setNames(month.name, format(ISOdate(2000, 1:12, 1), "%b"))
loc2eng["Jan"]
Or without using locales - hard coded:
de2de <- setNames(c("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli"
, "August", "September", "Oktober", "November", "Dezember"), c("Jan", "Feb"
, "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"))
de2de[c("Jan", "Feb", "Mär", "Apr", "Mai")]
# Jan Feb Mär Apr Mai
# "Januar" "Februar" "März" "April" "Mai"
This is what the function match
solves.
Using the built-in English names, you’d write
example_data = c('Jan', 'Dec', 'Mar')
month.name[match(example_data, month.abb)]
The same works for other languages, you’ll just have to define your own vectors for the month names and abbreviations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With