as_month: Coerce an object to month

View source: R/month.R

as_monthR Documentation

Coerce an object to month

Description

as_month() is a generic for coercing input in to ⁠<grates_month>⁠.

Usage

as_month(x, n, ...)

## Default S3 method:
as_month(x, n, ...)

## S3 method for class 'Date'
as_month(x, n, ...)

## S3 method for class 'POSIXt'
as_month(x, n, ...)

## S3 method for class 'character'
as_month(x, n, ...)

## S3 method for class 'factor'
as_month(x, n, ...)

Arguments

x

An R object.

Character input is first parsed using as.Date().

POSIXt inputs are converted with the timezone respected.

n

⁠[integer]⁠

Number of months that are being grouped. Must be greater than 1 (use as_yearmonth() for this case).

...

Only used For character input where additional arguments are passed through to as.Date().

Value

A ⁠<grates_month>⁠ object.

Note

Internally grates_month objects are stored as the position, starting at 0, of n-month groups since the Unix Epoch (1970-01-01). Here n-months is taken to mean a 'grouping of n consecutive months'. Precision is only to the month level (i.e. the day of the month is always dropped).

References

The algorithm to convert between dates and months relative to the UNIX Epoch comes from the work of Davis Vaughan in the unreleased datea package.

See Also

as.Date()

Examples

as_month("2019-05-03", n = 4L)
as_month(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"), n = 2)


grates documentation built on July 9, 2023, 7:09 p.m.