cal.yr {Epi}R Documentation

Function to convert character, factor and various date objects into a number.

Description

Dates are converted to a numerical value, giving the calendar year as a fractional number. 1 January 1970 is converted to 1970.0, and other dates are converted by assuming that years are all 365.25 days long, so inaccuracies may arise, for example, 1 Jan 2000 is converted to 1999.999. Differences between converted values will be 1/365.25 of the difference between corresponding Date objects.

Usage

  cal.yr(x, format)

Arguments

x A factor or character vector, representing a date in format format, or an object of class Date, POSIXlt, POSIXct, date, dates or chron (the latter two requires the chron package).
format Format of the date values if x is factor or character

Value

cal.yr returns a numerical vector of the same length as x.

Author(s)

Bendix Carstensen, Steno Diabetes Center & Dept. of Biostatistics, University of Copenhagen, bxc@steno.dk, http://www.pubhealth.ku.dk/~bxc

See Also

DateTimeClasses, Date

Examples

 birth <- c("14/07/1952","01/04/1954","10/06/1987","16/05/1990",
            "01/01/1996","01/01/1997","01/01/1998","01/01/1999")
 ( bt.yr <- cal.yr( birth, format="%d/%m/%Y" ) )
 # To get readable output:
 data.frame( birth, bt.yr )

[Package Epi version 0.4 Index]