complete.time.series: complete.time.series

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Add rows for missing measurements in time series.

Usage

1
2
complete.time.series(data, cond.col, lab.col, time.col, time.vector,
  meas.col, impute = FALSE)

Arguments

data

a data.table in long format with at least 4 columns: condition, label, time and measurement.

cond.col

column name for grouping. Typically an ID for experimental conditions.

lab.col

column name for second grouping. Typically an ID for trajectories. This ID can be shared between different conditions (first grouping).

time.col

column name of time.

time.vector

numerical vector. Over which time should ALL time series span? Missing times will be added to trajectory where it's not present.

meas.col

column name with measurements.

impute

logical. If TRUE, uses linear interpolation to replace NAs. Careful because this won't make the distinction between introduced NAs and the ones already present beforehand.

Value

A data.table with extra rows for missing measurements.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Simulate 10 phase-shifted sinusoids with 3 different level of noises
# ("experimental conditions", first grouping).
x <- multi_sims(type = "ps", noises = c(0.2,0.4), n = 10)
plot_sim(x)
# Remove 50 random rows
x[, row.nber := 1:nrow(x)] # For manually checking missing values
row_to_del <- sample(1:nrow(x), size = 50, replace = F)
row_to_keep <- setdiff(1:nrow(x), row_to_del)
x <- x[row_to_keep]
# Recreate the missing rows
x_complete <- complete.time.series(data = x,
 cond.col = "noise", lab.col = "variable",
 time.col = "Time", time.vector = unique(x$Time),
 meas.col = "value")

majpark21/TSexploreR documentation built on Oct. 16, 2019, 2:46 p.m.