link_gaps | R Documentation |
Gaps in mobile sensing data typically occur when the app is stopped by the operating system or
the user. While small gaps may not pose problems with analyses, greater gaps may cause bias or
skew your data. As a result, gap data should be considered in order to inspect and limit their
influence. This function, analogous to link()
, allows you to connect gaps to other data
(usually ESM/EMA data) within a user-specified time range.
link_gaps(
data,
gaps,
by = NULL,
offset_before = 0,
offset_after = 0,
raw_data = FALSE
)
data |
A data frame or an extension to a data frame (e.g. a tibble). While gap data can be linked to any other type of data, ESM data is most commonly used. |
gaps |
A data frame (extension) containing the gap data. See |
by |
A character vector indicating the variable(s) to match by, typically the participant
IDs. If NULL, the default, To join by different variables on To join by multiple variables, use a vector with To perform a cross-join (when |
offset_before |
The time before each measurement in |
offset_after |
The time after each measurement in |
raw_data |
Whether to include the raw data (i.e. the matched gap data) to the output as gap_data. |
The original data
with an extra column duration
indicating the gap during within the
interval in seconds (if duration
is TRUE
), or an extra column called gap_data
containing
the gaps within the interval. The function ensures all durations and gap time stamps are within
the range of the interval.
bin_data()
for linking two sets of intervals to each other; identify_gaps()
for
finding gaps in the sampling; add_gaps()
for adding gaps to sensor data;
# Create some data
x <- data.frame(
time = rep(seq.POSIXt(as.POSIXct("2021-11-14 13:00:00"), by = "1 hour", length.out = 3), 2),
participant_id = c(rep("12345", 3), rep("23456", 3)),
item_one = rep(c(40, 50, 60), 2)
)
# Create some gaps
gaps <- data.frame(
from = as.POSIXct(c("2021-11-14 13:00:00", "2021-11-14 14:00:00")),
to = as.POSIXct(c("2021-11-14 13:30:00", "2021-11-14 14:30:00")),
participant_id = c("12345", "23456")
)
# Link the gaps to the data
link_gaps(x, gaps, by = "participant_id", offset_before = 0, offset_after = 1800)
# Link the gaps to the data and include the raw data
link_gaps(
x,
gaps,
by = "participant_id",
offset_before = 0,
offset_after = 1800,
raw_data = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.