View source: R/interval-iterator.r
| time_interval_gen | R Documentation |
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.
time_interval_gen( x, time, start, end, duration, start_loc = TRUE, end_loc = TRUE )
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. |
hour_checkin_gen
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.