insertAloneTime: creates additional rows for new categories

View source: R/preprocessing.R

insertAloneTimeR Documentation

creates additional rows for new categories

Description

function to add rows for new types of observations (e.g., Alone).

Usage

insertAloneTime(
  dat,
  nestVars = NULL,
  timeVar = "date",
  catVar = "alter",
  insertNA = NULL,
  timeLag = 1
)

Arguments

dat

data.frame containing the relevant variables

nestVars

name(s) of the columns indicating how the data is nested (e.g., ID variable). Currently up to two nestVars are possible.

timeVar

column name indicating the time variable

catVar

column name indicating the category variable

insertNA

A vector with the variable names that should be filled with NAs for the "not-alone" state

timeLag

A positive number or vector with positive numbers indicating the time in the "not-alone" state. If a vector is provided random samples of the vector will be taken.

Value

data.frame with addtional rows

Examples

dat <- data.frame(ID = c(rep(1,10), rep(2,10)),
                 day = rep(c(rep(1,5), rep(2,5)),2),
                 a = runif(20, max = 10),
                 time = Sys.time()+1:20,
                 cat = sample(c("X","Y","Z"), 20, replace = T))

insertAloneTime(dat, nestVars = c("ID"), timeVar = "time", catVar = "cat")

timonelmer/dena documentation built on April 15, 2023, 11:51 p.m.