Learn R Programming

tsibble (version 0.6.1)

time_in: If time falls in the ranges using compact expressions

Description

This function respects time zone and encourages compact expressions.

Usage

time_in(x, ...)

Arguments

x

A vector of time index, such as classes POSIXct, Date, yearweek, yearmonth, yearquarter, hms/difftime, and numeric.

...

Formulas that specify start and end periods (inclusive) or strings.

  • ~ end or . ~ end: from the very beginning to a specified ending period.

  • start ~ end: from specified beginning to ending periods.

  • start ~ .: from a specified beginning to the very end of the data. Supported index type: POSIXct (to seconds), Date, yearweek, yearmonth/yearmon, yearquarter/yearqtr, hms/difftime & numeric.

Value

logical vector

See Also

filter_index for filtering tsibble

Examples

Run this code
# NOT RUN {
x <- unique(pedestrian$Date_Time)
lgl <- time_in(x, ~ "2015-02", "2015-08" ~ "2015-09", "2015-12" ~ "2016-02")
lgl[1:10]
# more specific
lgl2 <- time_in(x, "2015-03-23 10" ~ "2015-10-31 12")
lgl2[1:10]

pedestrian %>% 
  filter(time_in(Date_Time, "2015-03-23 10" ~ "2015-10-31 12"))
pedestrian %>% 
  filter(time_in(Date_Time, "2015")) %>% 
  mutate(Season = ifelse(
    time_in(Date_Time, "2015-03" ~ "2015-08"),
    "Autumn-Winter", "Spring-Summer"
  ))
# }

Run the code above in your browser using DataLab