Year Conversion from Rata Die
Source:R/AllGenerics.R
, R/calendar-gregorian.R
, R/calendar-julian.R
as_year.Rd
Year Conversion from Rata Die
Usage
as_year(object, calendar, ...)
# S4 method for class 'numeric,GregorianCalendar'
as_year(object, calendar, decimal = TRUE, ...)
# S4 method for class 'numeric,JulianCalendar'
as_year(object, calendar, decimal = FALSE, ...)
Arguments
- object
- calendar
A
TimeScale
object specifying the target calendar (seecalendar()
).- ...
Currently not used.
- decimal
A
logical
scalar: should decimal years be returned? IfFALSE
, the decimal part is dropped.
Value
A numeric
vector of (decimal) years.
References
Reingold, E. M. and Dershowitz, N. (2018). Calendrical Calculations: The Ultimate Edition. Cambridge University Press. doi:10.1017/9781107415058 .
See also
Other fixed date tools:
arithmetic
,
as_date()
,
as_decimal()
,
as_fixed()
,
fixed()
,
fixed_gregorian
,
fixed_julian
,
format()
,
pretty()
Examples
## R 1.0.0
(y <- fixed(year = 2000, month = 02, day = 29, calendar = CE()))
#> Rata die: number of days since 01-01-01 (Gregorian)
#> [1] 730179
as_date(y, calendar = CE())
#> year month day
#> 1 2000 2 29
as_year(y, calendar = CE())
#> [1] 2000.161
## Create a vector of years BP (Gregorian)
## (every two years starting from 2000 BP)
(years <- seq(from = 2000, by = -2, length.out = 10))
#> [1] 2000 1998 1996 1994 1992 1990 1988 1986 1984 1982
## Convert years to rata die
(rd <- fixed(years, calendar = BP()))
#> Rata die: number of days since 01-01-01 (Gregorian)
#> [1] -18627 -17897 -17166 -16436 -15705 -14975 -14244 -13514 -12783 -12053
## Convert back to Gregorian years BP
as_year(rd, calendar = BP())
#> [1] 2000 1998 1996 1994 1992 1990 1988 1986 1984 1982
## More convenient
(rd <- fixed_from_BP(years))
#> Rata die: number of days since 01-01-01 (Gregorian)
#> [1] -18627 -17897 -17166 -16436 -15705 -14975 -14244 -13514 -12783 -12053
fixed_to_BP(rd)
#> [1] 2000 1998 1996 1994 1992 1990 1988 1986 1984 1982