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 class character. Uses the format function.

format

If missing the value is drawn from the displayFormat property of x.

...

arguments passed to other methods (e.g., format).

as.numeric(x = "mondate",

convert=FALSE, stripdim=FALSE, timeunits=c("months", "years", "days"), ...) Coerce mondate to class numeric.

convert:

FALSE (the default) is equivalent to getDataPart. If TRUE the result will be converted to the number of years since the beginning of the millennium if timeunits="years"; to the number of days since the beginning of the millennium if timeunits="days". Also in the case that convert=TRUE the numeric returned will have "timeunits" as an attribute.

stripdim:

FALSE (the default) retains the array attributes dim and dimnames. If TRUE the dimension attributes are stripped, which is the default behavior of base::as.numeric.

timeunits

If missing the value is drawn from the property of the mondate.

as.Date(x = "mondate")

Coerce mondate to class Date

as.POSIXlt(x = "mondate")

Coerce mondate to class POSIXlt

as.POSIXct(x = "mondate")

Coerce mondate to class POSIXct

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

[Package mondate version 1.0 Index]