Learn R Programming

clock (version 0.7.1)

year-month-day-boundary: Boundaries: year-month-day

Description

This is a year-month-day method for the calendar_start() and calendar_end() generics. They adjust components of a calendar to the start or end of a specified precision.

Usage

# S3 method for clock_year_month_day
calendar_start(x, precision)

# S3 method for clock_year_month_day calendar_end(x, precision)

Value

x at the same precision, but with some components altered to be at the boundary value.

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
# Hour precision
x <- year_month_day(2019, 2:4, 5, 6)
x

# Compute the start of the month
calendar_start(x, "month")

# Or the end of the month, notice that the hour value is adjusted as well
calendar_end(x, "month")

# Compare that with just setting the day of the month to `"last"`, which
# doesn't adjust any other components
set_day(x, "last")

# You can't compute the start / end at a more precise precision than
# the input is at
try(calendar_start(x, "second"))

Run the code above in your browser using DataLab