mutate_delta: Mutate delta variable

View source: R/mutate_delta.R

mutate_deltaR Documentation

Mutate delta variable

Description

This function will create a delta variable given a subject id, variable name and dataframe. It will also skip NA values in the calculation of the delta.

Usage

mutate_delta(
  data,
  cols,
  id,
  time,
  fill = 0,
  n = 1L,
  type = "lag",
  prefix = paste("delta", type, n, sep = "_")
)

Arguments

data

the dataframe to be called

cols

the character string or character vector of columns to apply this function to

id

a character string specifying the name of the id variable

time

a character stirng the time variable

fill

numeric or NA to specifying what to fill the values that fall outside the offset window. For example, if we ar taking lagged differences, this will set the value of the firt observation.

n

number of steps to alter rolling difference window

type

character string whether lead or lag should be used

prefix

a character string denothing the prefix of the delta column. The column name for the new delta column will be "prefix_oldname"

Author(s)

Jorge Martinez Romero, William Mueller


wfmueller29/SLAM documentation built on April 5, 2025, 5:09 a.m.