Learn R Programming

ds4psy (version 0.2.0)

what_week: What week is it?

Description

what_week provides a satisficing version of to determine the week corresponding to a given date.

Usage

what_week(when = Sys.time(), unit = "year", as_integer = FALSE)

Arguments

when

Date (as a scalar or vector). Default: when = NA. Using as.Date(when) to convert strings into dates, and Sys.Date(), if when = NA.

unit

Character: Unit of week? Possible values are "month", "year". Default: unit = "year" (for week within year).

as_integer

Boolean: Return as integer? Default: as_integer = FALSE.

Details

what_week returns the week of when or Sys.Date() (as a name or number).

See Also

what_day() function to obtain days; what_date() function to obtain dates; cur_time() function to print the current time; cur_date() function to print the current date; now() function of the lubridate package; Sys.time() function of base R.

Other date and time functions: cur_date(), cur_time(), what_date(), what_day(), what_month(), what_time(), what_year()

Examples

Run this code
# NOT RUN {
what_week()
what_week(as_integer = TRUE)

# Other dates/times:
d1 <- as.Date("2019-08-23")
what_week(when = d1, unit = "year")
what_week(when = d1, unit = "month")

# Work with vectors (when as characters):
ds <- c("2020-01-01", "2020-02-29", "2020-12-24", "2020-12-31")
what_week(when = ds)
what_week(when = ds, unit = "month", as_integer = TRUE)
what_week(when = ds, unit = "year", as_integer = TRUE)
 
# }

Run the code above in your browser using DataLab