time_interval_gen: Create a time interval iterator generator

View source: R/interval-iterator.r

time_interval_genR Documentation

Create a time interval iterator generator

Description

The time interval generator creates an iterator, which iterates over consecutive periods of length duration. This function is a more general version of the hour_check_gen() function, which iterates over consecutive hours based on start and stop defined by the maximum and minimum times defined in a check data set.

Usage

time_interval_gen(
  x,
  time,
  start,
  end,
  duration,
  start_loc = TRUE,
  end_loc = TRUE
)

Arguments

x

the data frame of checkins.

time

the column denoting the timestamp.

start

the beginning of the interval.

end

the end of the interval.

duration

the period for each iteration.

start_loc

should the starting location be included? Default TRUE.

end_loc

should the starting location be included? Default TRUE.

See Also

hour_checkin_gen

Examples


library(lubridate)
library(dplyr)
library(purrr)

data(checkins)

# Create a data set for the first hour of the checkins data.
x <- checkins %>%
  filter(timestamp < min(timestamp) + hours(1))
 
# Create a generator for that hour with 15 minute durations.  

gen_15 <- partial(time_interval_gen,
                  start = min(x$timestamp), 
                  end = max(x$timestamp),
                  duration = minutes(15))

checkin_count <- function(it) {
  tibble(unique_ids = length(unique(it$id)), count = nrow(it))
}

# Count the number of checkins for each interval.
map_interval_dfr(x, gen_15, checkin_count, "timestamp")


kaneplusplus/checkin documentation built on Aug. 1, 2022, 1:11 p.m.