Learn R Programming

tsibble (version 0.9.2)

yearmonth: Represent year-month

Description

stable

Create or coerce using yearmonth().

Usage

yearmonth(x)

is_yearmonth(x)

Arguments

x

Other object.

Value

year-month (yearmonth) objects.

Display

Use format() to display yearweek, yearmonth, and yearquarter objects in required formats. Please see strptime() details for supported conversion specifications.

See Also

Other index functions: yearquarter(), yearweek()

Examples

Run this code
# NOT RUN {
# coerce POSIXct/Dates to yearmonth
x <- seq(as.Date("2016-01-01"), as.Date("2016-12-31"), by = "1 month")
yearmonth(x)

# parse characters
yearmonth(c("2018 Jan", "2018-01", "2018 January"))

# seq() and arithmetic
mth <- yearmonth("2017-11")
seq(mth, length.out = 10, by = 1) # by 1 month
mth + 0:9

# display formats
format(mth, format = "%y %m")

# units since 1970 Jan
as.double(yearmonth("1969 Jan") + 0:24)
# }

Run the code above in your browser using DataLab