Learn R Programming

clock (version 0.7.1)

year-month-day-widen: Widen: year-month-day

Description

This is a year-month-day method for the calendar_widen() generic. It widens a year-month-day vector to the specified precision.

Usage

# S3 method for clock_year_month_day
calendar_widen(x, precision)

Value

x widened to the supplied precision.

Arguments

x

[clock_year_month_day]

A year-month-day vector.

precision

[character(1)]

One of:

  • "year"

  • "month"

  • "day"

  • "hour"

  • "minute"

  • "second"

  • "millisecond"

  • "microsecond"

  • "nanosecond"

Examples

Run this code
# Month precision
x <- year_month_day(2019, 1)
x

# Widen to day precision
calendar_widen(x, "day")

# Or second precision
sec <- calendar_widen(x, "second")
sec

# Second precision can be widened to subsecond precision
milli <- calendar_widen(sec, "millisecond")
micro <- calendar_widen(sec, "microsecond")
milli
micro

# But once you have "locked in" a subsecond precision, it can't
# be widened again
try(calendar_widen(milli, "microsecond"))

Run the code above in your browser using DataLab