How to change days of week in dataframe to English

Viewed 24

I would like to change days of the week from Dutch to English, however, Sys.getlocale (category = "LC_ALL") and Sys.setlocale (category = "LC_ALL", locale = "English United States"), give the warning message : OS reports request to set locale to "English United States" cannot be honored.

The dataframe is:

daily_activity <- dailyActivity_merged %>%
      clean_names() %>%
      mutate(activity_date = mdy(activity_date), day_week = weekdays(activity_date))%>%
      rename(date=activity_date)

with following output:

> print(daily_activity)
            id       date total_steps total_distance  day_week
1   1503960366 2016-04-12       13162           8.50   dinsdag
2   1503960366 2016-04-13       10735           6.97  woensdag
3   1503960366 2016-04-14       10460           6.74 donderdag
4   1503960366 2016-04-15        9762           6.28   vrijdag
5   1503960366 2016-04-16       12669           8.16  zaterdag
6   1503960366 2016-04-17        9705           6.48    zondag
7   1503960366 2016-04-18       13019           8.59   maandag
8   1503960366 2016-04-19       15506           9.88   dinsdag

1 Answers

We could do it with Sys.setlocale: The source indicated by jspcal in the comments is a good source. In your case you just have to transform date column to date class (here we use lubridate package):

Sys.setlocale("LC_TIME","English_United States.1252")

library(lubridate)
library(dplyr)
df %>% 
  mutate(english_day=weekdays(ymd(date)))
          id       date total_steps total_distance  day_week english_day
1 1503960366 2016-04-12       13162           8.50   dinsdag     Tuesday
2 1503960366 2016-04-13       10735           6.97  woensdag   Wednesday
3 1503960366 2016-04-14       10460           6.74 donderdag    Thursday
4 1503960366 2016-04-15        9762           6.28   vrijdag      Friday
5 1503960366 2016-04-16       12669           8.16  zaterdag    Saturday
6 1503960366 2016-04-17        9705           6.48    zondag      Sunday
7 1503960366 2016-04-18       13019           8.59   maandag      Monday
8 1503960366 2016-04-19       15506           9.88   dinsdag     Tuesday
Related