Coersion-from-mondate methods {mondate} | R Documentation |
Coersion Methods for Mondates
Description
Methods to coerce a mondate
to other R objects.
Currently that includes numbers, characters,
and three classes of dates.
Usage
## S3 method for class 'mondate'
as.character(x, format, ...)
## S3 method for class 'mondate'
as.Date(x, ...)
## S3 method for class 'mondate'
as.POSIXct(x, ...)
## S3 method for class 'mondate'
as.POSIXlt(x, ...)
## S4 method for signature 'mondate'
as.numeric(x, convert = FALSE, stripdim = FALSE,
timeunits = c("months", "years", "days"),
...)
Arguments
x |
a mondate |
format |
the format to give the Date representation of x |
... |
arguments passed to and from other methods |
convert |
See Methods |
stripdim |
See Methods |
timeunits |
See Methods |
Methods
as.character(x = "mondate", format, ...)
-
Coerce
mondate
to classcharacter
. Uses theformat
function.format
-
If
missing
the value is drawn from thedisplayFormat
property ofx
. ...
-
arguments passed to other methods (e.g.,
format
).
as.numeric(x = "mondate",
-
convert=FALSE, stripdim=FALSE,
timeunits=c("months", "years", "days"), ...)
Coercemondate
to classnumeric
.convert:
-
FALSE
(the default) is equivalent togetDataPart
. IfTRUE
the result will be converted to the number of years since the beginning of the millennium iftimeunits
="years"; to the number of days since the beginning of the millennium iftimeunits
="days". Also in the case thatconvert=TRUE
thenumeric
returned will have "timeunits" as an attribute. stripdim:
-
FALSE
(the default) retains the array attributesdim
anddimnames
. IfTRUE
the dimension attributes are stripped, which is the default behavior ofbase::as.numeric
. timeunits
-
If
missing
the value is drawn from the property of themondate
.
as.Date(x = "mondate")
-
Coerce
mondate
to classDate
as.POSIXlt(x = "mondate")
-
Coerce
mondate
to classPOSIXlt
as.POSIXct(x = "mondate")
-
Coerce
mondate
to classPOSIXct
Examples
(b<-mondate(1)) # end of first month of current millennium
as.numeric(b) # 1
as.character(b) # December 31, 2000 in date format of locale
as.character(b, format="%b-%Y") # "Dec-2000"
as.numeric(b, convert=TRUE, timeunits="years") # converts to 1/12 "years"
(b<-mondate(1, timeunits="days")) # end of first day of millennium
as.numeric(b) # 1/31
as.numeric(b, convert=TRUE) # 1 (with a "days" attribute)
as.Date(b) # displays as "2000-01-31"
as.POSIXct(b) # displays as "2000-01-31 UTC"
weekdays(as.POSIXct(b)) # January 31, 2000 was a "Saturday" (in English)
as.POSIXlt(b)$hour # zero, as are ...$min and ...$sec