Learn R Programming

clock (version 0.7.1)

year-day-narrow: Narrow: year-day

Description

This is a year-day method for the calendar_narrow() generic. It narrows a year-day vector to the specified precision.

Usage

# S3 method for clock_year_day
calendar_narrow(x, precision)

Value

x narrowed to the supplied precision.

Arguments

x

[clock_year_day]

A year-day vector.

precision

[character(1)]

One of:

  • "year"

  • "day"

  • "hour"

  • "minute"

  • "second"

  • "millisecond"

  • "microsecond"

  • "nanosecond"

Examples

Run this code
# Hour precision
x <- year_day(2019, 3, 4)
x

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

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

# Subsecond precision can be narrowed to second precision
milli <- calendar_widen(x, "millisecond")
micro <- calendar_widen(x, "microsecond")
milli
micro

calendar_narrow(milli, "second")
calendar_narrow(micro, "second")

# But once you have "locked in" a subsecond precision, it can't be
# narrowed to another subsecond precision
try(calendar_narrow(micro, "millisecond"))

Run the code above in your browser using DataLab