regularise_time: regularise_time

Description Usage Arguments Examples

View source: R/SL_tbl_trans.R

Description

Transform an SL_tibble (as produced by load_SL_tibble) in such a way that the observations are aggregated in equal length intervals called 'blocks' (for more information on blocks see add_block_labels).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
regularise_time(
  tab,
  ...,
  blocks = c("epoch", "day"),
  add_NAs = TRUE,
  unsafe = F,
  study_duration = getOption("SL_duration"),
  start_date = getOption("SL_start"),
  epoch_levels = getOption("SL_epoch_levels"),
  epoch_ubs = getOption("SL_epoch_ubs"),
  uid_range = getOption("SL_uids"),
  date_range = seq(from = start_date, by = 1, length.out = study_duration)
)

Arguments

tab

An SL_tibble as returned by the function load_SL_tibble. The SL_tibble must have some date-time information.

...

Arguments passed to summarise, used to aggregate values when multiple observations are encountered in a block. Any columns not specified here or under blocks will be dropped.

blocks

A character vector naming one or more of the block options "hour_in_day", "epoch", "day", "week", "weekday", "month" or "date". If not present as column names in tab, an attempt will be made to infer the blocks from existing time information with add_block_labels. The returned data.frame will have one observation (possibly NA) for each block.

add_NAs

A logical. If TRUE then NAs will be introduced to fill missing blocks.

unsafe

A logical. Default is FALSE. If this is set to TRUE then less checks will be performed.

study_duration

Integer. The duration of the StudentLife study in days. This parameter does nothing if limit_date_range it TRUE.

start_date

Date. The date that the StudentLife study started.

epoch_levels

A character vector of epoch labels.

epoch_ubs

An integer vector that defines the hour that is the upper boundary of each epoch.

uid_range

An integer vector. The range of uids in the StudentLife study.

date_range

A vector of dates to be used if limit_date_range is FALSE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
d <- tempdir()
download_studentlife(location = d, url = "testdata")

tab <- load_SL_tibble(
  loc = d, schema = "sensing", table = "activity", csv_nrows = 10)

r_tab <- regularise_time(
  tab, blocks = c("day","weekday"),
  act_inf = max(activity_inference), add_NAs = FALSE)

r_tab

frycast/studentlife documentation built on April 25, 2021, 11:09 a.m.