| timeToPeriod {dembase} | R Documentation |
Convert a vector of years to a vector of periods.
The periods are formatted in the way expected by
functions such as Counts and
Values.
timeToPeriod(year, breaks, firstOpen = FALSE, lastOpen = FALSE)
year |
A vector of years. A numeric vector, or a vector than can be coerced to numeric. |
breaks |
A vector of breaks, specifying the points dividing periods. |
firstOpen |
Logical. Whether the first period is "open",
i.e. has no lower bound. Defaults to |
lastOpen |
Logical. Whether the last period is "open",
i.e. has no upper bound. Defaults to |
The years can be contain decimal fractions such as 2000.25 or
2018.633, but are more typically integers
such as 2000 or 2018.
If year is a factor, then timeToPeriod will coerce
it to a character vector before trying to coerce it to numeric.
See below for an example.
A factor, the same length as year.
year <- c(2001, 2023, 2000, 2005, 2014, 2013, 2029) ## 5-year periods, 2000-2005, 2005-2010, ..., 2025-2030 timeToPeriod(year, breaks = seq(2000, 2030, 5)) ## 5-year periods, 2000-2005, 2005-2010, ..., 2045-2050 timeToPeriod(year, breaks = seq(2000, 2050, 5)) ## first period open timeToPeriod(year, breaks = seq(2010, 2030, 5), firstOpen = TRUE)