R: Narrow a calendar to a less precise precision

calendar_narrow {clock} | R Documentation

## Narrow a calendar to a less precise precision

### Description

`calendar_narrow()` narrows `x` to the specified `precision`. It does so by dropping components that represent a precision that is finer than `precision`.

Each calendar has its own help page describing the precisions that you can narrow to:

- year-month-day

- year-month-weekday

- iso-year-week-day

- year-quarter-day

- year-day

### Usage

    calendar_narrow(x, precision)

### Arguments

`x` | `[calendar]` A calendar vector.
`precision` | `[character(1)]` A precision. Allowed precisions are dependent on the calendar used.

### Details

A subsecond precision `x` cannot be narrowed to another subsecond precision. You cannot narrow from, say, `"nanosecond"` to `"millisecond"` precision. clock operates under the philosophy that once you have set the subsecond precision of a calendar, it is "locked in" at that precision. If you expected this to use integer division to divide the nanoseconds by 1e6 to get to millisecond precision, you probably want to convert to a time point first, and use `time_point_floor()`.

### Value

`x` narrowed to the supplied `precision`.

### Examples

    # Hour precision
    x <- year_month_day(2019, 1, 3, 4)
    x

    # Narrowed to day precision
    calendar_narrow(x, "day")

    # Or month precision
    calendar_narrow(x, "month")

[Package clock version 0.6.0 Index]