Arith-methods {mondate} | R Documentation |
Arithmetic methods for class mondate
.
Includes three special "subtraction" methods.
signature(e1 = "mondate", e2 = "mondate")
Performs arithmetic operations on two mondate
s.
The result will be numeric
with attribute timeunits
belonging to the slot of the first argument
(with a warning if the two arguments have different timeunits
).
The only operation that would seem useful for two
mondate
s is subtraction.
signature(e1 = "mondate", e2 = "numeric")
signature(e1 = "numeric", e2 = "mondate")
Performs arithmetic operations of a numeric
on a
mondate
where the units
of the numeric
is taken from the
timeunits
slot of the mondate
.
The result will be a mondate
with the same properties
as the mondate
in the function call.
The only operations that would seem useful for a mondate
and a numeric
are addition and subtraction.
Most of the time it is expected that timeunits
="months" so that,
for example,
adding/subtracting a number to/from that mondate
adds/subtracts that
number of months.
If the mondate
's timeunits
="years"
then the perceived intention is to
add/subtract that number of years.
To accomplish that, the mondate
's numeric
value is divided by 12, the operation is performed, and the result converted
to a mondate
.
If the mondate
's timeunits
="days",
then the mondate
's value is converted to the number
of days since the start of the millennium,
the operation is performed
(e.g., the numeric
number of days is added or subtracted),
and the result converted to a mondate
.
(See the convert
option of the as.numeric("mondate")
function.)
MonthsBetween(from = "mondate", to = "mondate")
Same as from
-to
if timeunits
of to
= "months".
YearsBetween(from = "mondate", to = "mondate")
Same as from
-to
if timeunits
of to
= "years".
DaysBetween(from = "mondate", to = "mondate")
Same as from
-to
if timeunits
of to
= "days".
M<-mondate("1-1-2010") # will display in U.S. date format M-1:12 # the 1st of the month for all months in 2009 # in reverse chronological order; inherits M's displayFormat x <- mondate(matrix(12*1:4,2,2)) # 2x2 matrix of 2000-2003 year ends x y<-x+12 # one year later, also a matrix y y-x # 2x2 matrix of 12s, with an attribute ("months") MonthsBetween(x,y) # same, without the attribute YearsBetween(x,y) DaysBetween(x,y)