date2ISOweek: Converts date from standard notation to week notation...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/date2ISOweek.R

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

1

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 u.block.mz@googlemail.com

See Also

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

Examples

1
2
3
4
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))

Example output

         date   weekdate
1  1999-12-31 1999-W52-5
2  2000-12-31 2000-W52-7
3  2001-12-31 2002-W01-1
4  2002-12-31 2003-W01-2
5  2003-12-31 2004-W01-3
6  2004-12-31 2004-W53-5
7  2005-12-31 2005-W52-6
8  2006-12-31 2006-W52-7
9  2007-12-31 2008-W01-1
10 2008-12-31 2009-W01-3
11 2009-12-31 2009-W53-4
12 2010-12-31 2010-W52-5
13 2011-12-31 2011-W52-6
         date   weekdate
1  1999-12-31 1999-W52-5
2  2000-12-31 2000-W52-7
3  2001-12-31 2002-W01-1
4  2002-12-31 2003-W01-2
5  2003-12-31 2004-W01-3
6  2004-12-31 2004-W53-5
7  2005-12-31 2005-W52-6
8  2006-12-31 2006-W52-7
9  2007-12-31 2008-W01-1
10 2008-12-31 2009-W01-3
11 2009-12-31 2009-W53-4
12 2010-12-31 2010-W52-5
13 2011-12-31 2011-W52-6

ISOweek documentation built on May 1, 2019, 10:08 p.m.