Learn R Programming

aweek (version 0.2.2)

print.aweek: The aweek class

Description

The method c.aweek() will always return an aweek object with the same week_start attribute as the first object in the list. If the first object is also a factor, then the output will be re-leveled. If week-like characters are presented (e.g. "2019-W10-1"), then these are assumed to have the same week_start as the first object.

Usage

# S3 method for aweek
print(x, ...)

# S3 method for aweek [(x, i)

# S3 method for aweek c(..., recursive = FALSE, use.names = TRUE)

Arguments

x

an object of class aweek

...

a series of aweek objects (unused in print.aweek())

i

index for subsetting an aweek object.

recursive, use.names

parameters passed on to unlist()

Value

an object of class aweek

Details

The aweek class is a character or factor in the format YYYY-Www(-d) with a "week_start" attribute containing an integer specifying which day of the ISO 8601 week each week should begin. This documentation shows how to print or subset the object.

See Also

date2week(), as.Date.aweek()

Examples

Run this code
# NOT RUN {
d <- as.Date("2018-12-20") + 1:40
w <- date2week(d, week_start = "Sunday")
print(w)

# subsetting acts as normal
w[1:10]

# Combining multiple aweek objects
c(w[1], w[3], w[5])

# differing week_start days will default to the attribute of the first 
# aweek object
mon <- date2week(Sys.Date(), week_start = "Monday")
mon
c(w, mon)
c(mon, w)

# combining Dates will be coerced to aweek objects under the same rules
c(w, Sys.Date())

# truncated aweek objects will be un-truncated
w2 <- date2week(d[1:5], week_start = "Monday", floor_day = TRUE)
w2
c(w[1:5], w2)
# }

Run the code above in your browser using DataLab