Learn R Programming

clock (version 0.7.1)

date_weekday_factor: Convert a date or date-time to a weekday factor

Description

date_weekday_factor() converts a date or date-time to an ordered factor with levels representing the weekday. This can be useful in combination with ggplot2, or for modeling.

Usage

date_weekday_factor(
  x,
  ...,
  labels = "en",
  abbreviate = TRUE,
  encoding = "western"
)

Value

An ordered factor representing the weekdays.

Arguments

x

[Date / POSIXct / POSIXlt]

A date or date-time vector.

...

These dots are for future extensions and must be empty.

labels

[clock_labels / character(1)]

Character representations of localized weekday names, month names, and AM/PM names. Either the language code as string (passed on to clock_labels_lookup()), or an object created by clock_labels().

abbreviate

[logical(1)]

If TRUE, the abbreviated weekday names from labels will be used.

If FALSE, the full weekday names from labels will be used.

encoding

[character(1)]

One of:

  • "western": Encode the weekdays as an ordered factor with levels from Sunday -> Saturday.

  • "iso": Encode the weekdays as an ordered factor with levels from Monday -> Sunday.

Examples

Run this code
x <- as.Date("2019-01-01") + 0:6

# Default to Sunday -> Saturday
date_weekday_factor(x)

# ISO encoding is Monday -> Sunday
date_weekday_factor(x, encoding = "iso")

# With full names
date_weekday_factor(x, abbreviate = FALSE)

# Or a different language
date_weekday_factor(x, labels = "fr")

Run the code above in your browser using DataLab