The wday() function in the lubridate package with the option label = TRUE returns the name of the day of the week in English. I'd like to know if it is possible to get the name of day of the week in another language. Is there any option for that ?
Not without writing your own method.
The days of the week are hardcoded in English in lubridate:::wday.numeric
labels <- c("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday")
You could tweak the code from my answer here and replace the English names with names in the language of your choice.
# assuming x is your Date
c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday")[as.POSIXlt(x)$wday + 1]
Edit:
Here is a version that more closely matches lubridate
labels <- c("dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi")
ordered(as.POSIXlt(x)$wday + 1, levels=1:7, labels=labels)
Sys.setlocale("LC_TIME", "French")
, lubridate
's wday
returns french labels. –
Oe New answer to an old question:
Either tell your system to use French throughout:
Sys.setlocale("LC_TIME", "French")
Or set it within the function itself:
day <- seq(ymd("2018-01-01"), ymd("2018-01-08"), "day")
wday(day, label = TRUE, abbr = TRUE, locale = "EN-us")
[1] Mon Tue Wed Thu Fri Sat Sun Mon
Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
wday(day, label = TRUE, abbr = TRUE, locale = "French")
[1] lun\\. mar\\. mer\\. jeu\\. ven\\. sam\\. dim\\. lun\\.
Levels: dim\\. < lun\\. < mar\\. < mer\\. < jeu\\. < ven\\. < sam\\.
I've got to figure out why the labels are showing up with slashes though. I've asked the package maintainers about this because the month labels aren't showing up properly either (for me).
https://github.com/tidyverse/lubridate/issues/1127
One hint that helped me get proper months (e.g., février not f<e9>vrier) was to change the encoding, e.g., use locale = "fr_CA.utf8"
... but this didn't fix the weekday labels.
© 2022 - 2024 — McMap. All rights reserved.
weekdays
. – Jabez