Description Usage Arguments Details Examples
View source: R/complete_time.R
complete_time
adds missing timestamps to a data frame.
1 | complete_time(data, time, difference)
|
data |
The data frame containing the timestamps. |
difference |
The supposed difference between two timestamps. |
timestamp |
The timestamp column in the data frame. |
Completes a timestamp column by turning implicit missing values into explicit missing values, followed by a linear interpolation between missing values.
The data frame can be grouped using dplyr's group_by
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | library(dplyr)
# Example 1: Simple data
df <- tibble(
timestamp = 1:30,
trial = rep(1:3, each = 10),
event = rep(c(rep("baseline", 3), rep("event", 7)), times = 3)
)
# Remove some random observations, creating implicit missing values
set.seed(2020)
df <- slice_sample(df, n = 20) %>%
arrange(trial, timestamp)
# Add missing rows
df <- complete_time(df, timestamp, difference = 1)
# Example 2: Realistic data
missing_complete <- complete_time(missing, timestamp, difference = 1000/60)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.