last_n_years: Start and end of last n years

View source: R/last_n_years.R

last_n_yearsR Documentation

Start and end of last n years

Description

Defines first and last date in previous period

Usage

last_n_years(x = Sys.Date(), 
             n = 1, 
			       part = getOption("timeperiodsR.parts"), 
		         include_current = F)

Arguments

x

Date object

n

Number of periods for offset

part

Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details.

include_current

If TRUE incliding current period in sequence

Details

You can get object of tpr class with all components or specify which component you need, use part for manage this option:

  • all - get all components

  • start - get only first date of period

  • end - get only last date of period

  • start - get vector of all dates in period

  • length - get number of dates in period

Value

Object of tpr class

Author(s)

Alexey Seleznev

See Also

For get next other periods see last_n_months(), last_n_days(), last_n_weeks(), last_n_quarters()

Examples

## To get start, end and sequence of last 2 years, 
## exclude current year
last2years <- last_n_years(n = 2)

## include current year
last2years_2 <- last_n_years(n = 2, include_current = TRUE)

## To get vector of date sequences 
last_n_years(n = 2, part = "sequence")
last_n_years(n = 2)$sequence
seq(last2years)

## Get number of days of last 2 years
day_nums <- last_n_years(n = 2, part = "length")
last_n_years()$length
length(last2years)

selesnow/timeperiodsR documentation built on Jan. 27, 2024, 7:32 a.m.