Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

French names using wday in lubridate

Tags:

r

lubridate

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 ?

like image 276
PAC Avatar asked Oct 03 '22 11:10

PAC


1 Answers

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)
like image 117
GSee Avatar answered Oct 11 '22 19:10

GSee