within-interval: Tests whether a date or interval falls within an interval

Description Usage Arguments Value Examples

Description

recycled according to standard R rules. If b is a list of intervals, a is checked if it falls within any of the intervals in b. If a is an interval, both its start and end dates must fall within b to return TRUE.

Usage

1
a %within% b

Arguments

a

An interval or date-time object

b

An interval or a list of intervals (see examples)

Value

A logical

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
int <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
int2 <- interval(ymd("2001-06-01"), ymd("2002-01-01"))

ymd("2001-05-03") %within% int # TRUE
int2 %within% int # TRUE
ymd("1999-01-01") %within% int # FALSE

## recycling
dates <- ymd(c("2014-12-20", "2014-12-30", "2015-01-01", "2015-01-03"))
blackouts<- c(interval(ymd("2014-12-30"), ymd("2014-12-31")),
              interval(ymd("2014-12-30"), ymd("2015-01-03")))
dates %within% blackouts

## within ANY of the intervals of a list
dates <- ymd(c("2014-12-20", "2014-12-30", "2015-01-01", "2015-01-03"))
blackouts<- list(interval(ymd("2014-12-30"), ymd("2014-12-31")),
                 interval(ymd("2014-12-30"), ymd("2015-01-03")))
dates %within% blackouts

lubridate documentation built on April 11, 2018, 5:03 p.m.