Learn R Programming

timeperiodsR (version 0.7.3)

previous_week: Start and end of previous week

Description

Defines first and last date in n previous week

Usage

previous_week(x = Sys.Date(),
              n = 1, 
              part = getOption("timeperiodsR.parts"),
              week_start = 1)

Value

Object of tpr class

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.

week_start

Start of week, default = 1 is Monday, 7 is Sunday

Author

Alexey Seleznev

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

See Also

For get next other periods see previous_quarter(), previous_month(), previous_year()

Examples

Run this code
## To get start, end and sequence of previous weeks
previousweek <- previous_week()

## Get previous week with start on Sunday
previousweeksun <- previous_week(week_start = 7)

## To get vector of date sequences 
previous_week(part = "sequence")
previous_week()$sequence
seq(previousweek)

## Get number of days of previous 2 weeks
day_nums <- previous_week(part = "length")
previous_week()$length
length(previousweek)

Run the code above in your browser using DataLab