thicken_cust: Thicken with a custom spanning

View source: R/thicken_cust.R

thicken_custR Documentation

Thicken with a custom spanning

Description

Like thicken, it will find the datetime variable in x and add a variable of a higher periodicity to it. However, the variable to which to map the observation is provided by the user. This enables mapping to time points that are unequally spaced.

Usage

thicken_cust(x, spanned, colname, by = NULL, drop = FALSE)

Arguments

x

A data frame containing at least one datetime variable of class Date, POSIXct or POSIXlt.

spanned

A datetime vector to which the the datetime variable in x should be mapped.

colname

Character, the column name of the added variable.

by

Only needs to be specified when x contains multiple variables of class Date, POSIXct or POSIXlt. Indicates which to use for thickening.

drop

Should the original datetime variable be dropped from the returned data frame? Defaults to FALSE.

Details

Only rounding down is available for custom thickening.

Value

The data frame x with the variable added to it.

Examples

library(dplyr)
# analysis of traffic accidents in traffic jam hours and other hours.
accidents <- emergency %>% filter(title == "Traffic: VEHICLE ACCIDENT -")
spanning <- span_time("20151210 16", "20161017 17", tz = "EST") %>%
  subset_span(list(hour = c(6, 9, 16, 19)))
thicken_cust(accidents, spanning, "period") %>%
  count(period) %>%
  pad_cust(spanning)

padr documentation built on Nov. 23, 2022, 5:06 p.m.