Description Usage Arguments Details Value See Also Examples
View source: R/miscellaneous-functions.R
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
.
1 | 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
.
1 2 3 4 5 6 7 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.