Package 'ISOweek'

Title: Week of the year and weekday according to ISO 8601
Description: This is an substitute for the %V and %u formats which are not implemented on Windows. In addition, the package offers functions to convert from standard calender format yyyy-mm-dd to and from ISO 8601 week format yyyy-Www-d.
Authors: Uwe Block <[email protected]>, using an algorithm by Hatto von Hatzfeld <[email protected]>
Maintainer: Uwe Block <[email protected]>
License: GPL (>= 2)
Version: 0.6-2
Built: 2024-11-29 08:45:19 UTC
Source: CRAN

Help Index


Converts date from standard notation to week notation according to ISO 8601

Description

This function returns the year, the week of the year, and the day of week of a given date according to ISO 8601. It is an substitute for the %Y-W%V-%u format which is not implemented on Windows.

Usage

date2ISOweek(date)

Arguments

date

Vector which can be coerced to class Date

Details

According to ISO 8601, the year of the week can differ from the calendar year (see the examples).

Value

A character vector of year, week, and weekday in format "%Y-W%V-%u"

Author(s)

Uwe Block [email protected]

See Also

strptime for a description of the date formats and references on ISO 8601.

Examples

x <- paste(1999:2011, "-12-31", sep = "")
y <- as.Date(x)
data.frame(date = format(y), weekdate = date2ISOweek(y))
data.frame(date = x, weekdate = date2ISOweek(x))

Week of the year according to ISO 8601

Description

This function returns the year and the week of the year of a given date according to ISO 8601. It is an substitute for the %Y-W%V format which is not implemented on Windows.

Usage

ISOweek(date)

Arguments

date

Vector which can be coerced to class Date

Details

According to ISO 8601, the year of the week can differ from the calendar year (see the examples).

Value

A character vector of year and week in format "%Y-W%V"

Author(s)

Hatto von Hatzfeld [email protected], adopted to R by Uwe Block [email protected]

References

http://www.salesianer.de/util/kalwoch.html

See Also

strptime for a description of the date formats and references on ISO 8601. isoWeekYear for an alternative implementation.

Examples

x <- paste(1999:2011, "-12-31", sep = "")
y <- as.Date(x)
data.frame(date = format(y), week = ISOweek(y))
data.frame(date = x, week = ISOweek(x))

Converts date from week notation according to ISO 8601 to standard notation

Description

This function returns the date of a given weekdate (year, week of the year, day of week according to ISO 8601). It is the inverse function to date2ISOweek.

Usage

ISOweek2date(weekdate)

Arguments

weekdate

A character vector of year, week, and weekday in format "%Y-W%V-%u"

Details

According to ISO 8601, the year of the week can differ from the calendar year (see the examples).

Value

A vector of class Date

Author(s)

Uwe Block [email protected]

See Also

strptime for a description of the date formats and references on ISO 8601.

Examples

w <- paste("2009-W53", 1:7, sep = "-")
data.frame(weekdate = w, date = ISOweek2date(w))
# convert from calendar date to week date and back to calendar date
x <- paste(1999:2011, "-12-31", sep = "")
w <- date2ISOweek(x)
d <- ISOweek2date(w)
data.frame(date = x, weekdate = w, date2 = d)

Day of week according to ISO 8601

Description

This function returns the weekday of a given date according to ISO 8601. It is an substitute for the "%u" format which is not implemented on Windows.

Usage

ISOweekday(date)

Arguments

date

Vector which can be coerced to class Date

Value

An integer vector of weekdays (1-7, Monday is 1)

Author(s)

Uwe Block [email protected]

See Also

strptime

Examples

x <- paste(1999:2011, "-12-31", sep = "")
y <- as.Date(x)
data.frame(date = format(y), weekday = ISOweekday(y))
data.frame(date = x, weekday = ISOweekday(x))