Description Usage Arguments Details Value See Also Examples
View source: R/miscellaneous-functions.R
Calculates ages in completed years, periods, birth cohorts, or Lexis triangles from dates.
1 2 3 4 5 6 7 8 9 10 11 12 13 | datesToAgeGroups(date, dob, step = "1 year", lastOpen = TRUE)
datesToCohorts(dob, step = "years", monthStart = "January", yearStart = 2000)
datesToPeriods(date, step = "years", monthStart = "January", yearStart = 2000)
datesToTriangles(
date,
dob,
step = "years",
monthStart = "January",
yearStart = 2000
)
|
date |
A vector of class |
dob |
A vector of class |
step |
Length of age-time step. |
lastOpen |
Whether last age interval is open on the right. |
monthStart |
The English name of a month (as defined by
|
yearStart |
An integer. Controls the start date of multi-year periods. |
If date
and dob
are different lengths, the shorter
vector is recycled.
By default, age-time steps are assumed to be equal to one year. However,
alternative lengths can be specified, via the step
argument.
The steps are described as multiples of years, quarters or months.
If no multiple is provided, it is assumed to equal one.
Typical values are "5 years"
, "month"
,
"quarter"
, and "6 months"
. If a step length is less than 1
year, then it must divide the year without leaving a remainder.
Thus, for example, "4 months"
is a valid value for step
,
but "5 months"
is not.
By default, periods of one year are assumed to start on 1 January.
Other starting months can be specified via monthStart
.
See below for examples.
Multi-year periods are assumed to start on years beginning with 0 or 5.
Other values can be specified via yearStart
. See below for examples.
These functions handle leap years differently from seq.Date
.
Like most people, but unlike seq.Date
, they treat 29 February
as if it was 28 February. For instance, with datesToAge
, a
person who was born on 29 February 2000 reaches age 1 on 28 February 2001.
With seq.Date
, they reach age 1 on 1 March 2001.
A factor.
Vectors of class Date
can be created with
function as.Date
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | date <- as.Date(c("2005-07-05", "2006-06-30", "2008-07-05"))
dob <- as.Date(c("2005-06-30", "2005-06-30", "2006-07-01"))
datesToAgeGroups(date = date, dob = dob)
datesToAgeGroups(date = date, dob = dob, lastOpen = FALSE)
datesToAgeGroups(date = date, dob = dob, step = "2 years")
datesToAgeGroups(date = date, dob = dob, step = "quarter")
datesToAgeGroups(date = date, dob = dob, step = "month")
datesToPeriods(date = date)
datesToPeriods(date = date, monthStart = "July")
datesToPeriods(date = date, step = "2 years", yearStart = 2001)
datesToPeriods(date = date, step = "quarter")
datesToCohorts(dob)
datesToCohorts(dob, step = "2 quarters")
datesToTriangles(date = date, dob = dob)
datesToTriangles(date = date, dob = dob, step = "2 years")
datesToTriangles(date = date, dob = dob, monthStart = "April")
## 'date' must be later than 'dob'
## Not run:
datesToAgeGroups(date = as.Date("2000-01-01"), dob = as.Date("2005-01-01"))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.