| Calendar year {Epi} | R Documentation |
Dates are converted to a numerical value, so that 1 January
1970 is converted to 1970.0. The result is given a class
attribute, cal.yr. The function is intended for epidemiological
use, and the dates are converted to a calendar time scale that has 4
years of equal length between 1.1.1970 and 1.1.1974 etc. The printing of
cal.yr objects in human readable form may therefore be as much
as 3 days wrong.
cal.yr(x, format) dmy.cal.yr( d, m, y ) mdy.cal.yr( m, d, y ) ymd.cal.yr( y, m, d ) weekdays.cal.yr( x, abbreviate=FALSE ) weeks( x ) weeks.cal.yr( x ) months.cal.yr( x, abbreviate=FALSE ) print.cal.yr( x, format="%d/%m/%Y", ... )
x |
A character vector, representing a date in format
format, or an object of class POSIXt or
Date. |
d, m, y |
Numerical vectors representing, date month and year. |
format |
Optional character values giving the format for the date
if given as character. See the help page for strptime for
admissible values. |
abbreviate |
Should names be abbreviated? |
... |
Ignored, but present for compatibility with print methods |
cal.yr returns a numerical vector of the same length as
x. The associated print method, print.cal.yr prints the
dates in human readable format. To see the dates as fractions of
years, use as.numeric(cy).
dmy.cal.yr, mdy.cal.yr and ymd.cal.yr are
convenience functions for converting separate numerical variables
with date d, month m and year y into dates of
class cal.yr. These functions also accept a single character
variable as input, with two digits for day and month and four for year
and any delimiters.
weekdays.cal.yr, weeks.cal.yr and months.cal.yr,
extract weekday, week number and month from calendar year
objects. weekdays and months return factors with 7 and
12 levels respectively, regardless of the actually occurring number of
levels. weeks return numeric values in the range 1–52.
Bendix Carstensen, Steno Diabetes Center & Dept. of Biostatistics, University of Copenhagen, http://www.biostat.ku.dk/~bxc
birth <- c("14/07/1952", "01/04/1954", "10/06/1987")
( bt.yr <- cal.yr( birth, format="%d/%m/%Y" ) )
as.numeric( bt.yr )
weeks( bt.yr )
months( bt.yr )
( bt.y <- dmy.cal.yr( birth ) )