last_n_months: Start and end of last n months

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/last_n_months.R

Description

Defines first and last date in previous period

Usage

1
2
3
4
last_n_months(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:

Value

Object of tpr class

Author(s)

Alexey Seleznev

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## To get start, end and sequence of last 2 months, 
## exclude current month
last2month <- last_n_months(n = 2)

## include current month
last2month_2 <- last_n_months(n = 2, include_current = TRUE)

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

## Get number of days of last 2 months
day_nums <- last_n_months(n = 2, part = "length")
last_n_months()$length
length(last2month)

timeperiodsR documentation built on April 3, 2020, 9:10 a.m.