Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the english weekday abbreviation?

I have a Problem with setting the abbreviation of weekdays in some time Data. What I need are the abbreviations "Mon, Tues, Wed, Thurs, Fri, Sat, Sun". The lubridate::wday() function I work with gives the values "Mon, Tue, Wed, Thu, Fri, Sat, Sun".

It's a small difference for the days "Tuesday" and "Thursday".

x <- seq(Sys.Date() - 7, Sys.Date(), by = 1)
lubridate::wday(x, label = TRUE)
## [1] Thu Fri Sat Sun Mon Tue Wed Thu

I also changed the language-settings with locale, but this didn't do the trick because I'm not sure about the possible parameters to set (possible selections).

lubridate::wday(x, label = TRUE, locale = "French")
## [1] jeu\\. ven\\. sam\\. dim\\. lun\\. mar\\. mer\\. jeu\\.

lubridate::wday(x, label = TRUE, locale = "English")
## [1] Thu Fri Sat Sun Mon Tue Wed Thu

lubridate::wday(x, label = TRUE, locale = "English_Great Britain")
## [1] Thu Fri Sat Sun Mon Tue Wed Thu

lubridate::wday(x, label = TRUE, locale = "English_United States")
## [1] Thu Fri Sat Sun Mon Tue Wed Thu

The Difference might come from a change in my R Version (Now 3.4.2), as there was mentioned a change in this new Version concerning this subject... (https://cran.r-project.org/bin/windows/base/NEWS.R-3.4.2.html --> Setting the LC_ALL category in Sys.setlocale() invalidates any cached locale-specific day/month names and the AM/PM indicator for strptime() (as setting LC_TIME has since R 3.1.0)

System - Information:

R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.4.2  imsbasics_1.8.0 magrittr_1.5    tools_3.4.2     simtimer_2.0.18 Rcpp_0.12.12    lubridate_1.7.1
 [8] schedule_1.0.0  stringi_1.1.5   stringr_1.2.0  
like image 482
MichiSmith Avatar asked Dec 06 '25 07:12

MichiSmith


1 Answers

Since you want non-standard abbreviations, you'll need to do it manually:

x <- seq(Sys.Date() - 7, Sys.Date(), by = 1)
Sys.setlocale("LC_TIME", "C") #since I'm at a non-English locale
factor(weekdays(x, TRUE), 
       levels = c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"),
       labels = c("Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"))
#[1] Thurs Fri   Sat   Sun   Mon   Tues  Wed   Thurs
#Levels: Mon Tues Wed Thurs Fri Sat Sun

I'm not sure why you believe this to be related to R versions ...

like image 86
Roland Avatar answered Dec 07 '25 22:12

Roland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!