complete_time: Complete time

Description Usage Arguments Details Examples

View source: R/complete_time.R

Description

complete_time adds missing timestamps to a data frame.

Usage

1
complete_time(data, time, difference)

Arguments

data

The data frame containing the timestamps.

difference

The supposed difference between two timestamps.

timestamp

The timestamp column in the data frame.

Details

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.

Examples

 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)

WillemSleegers/eyepatch documentation built on Aug. 2, 2021, 8:39 a.m.