esm_day_lag: Lag day-level (or wave-level, month-level, week-level)...

Description Usage Arguments Details

Description

This function will lag any variable at an aggregated level above the observation level (usually the day level). It takes a dataset, a character vector of variables, and a character vector of grouping variables (by default the person and day ids), slices the first value within each group, lags these, then merges the result back into the original dataframe. The result is that any aggregated variable (e.g. the daily mean of a certain variable) will have all its (identical) values from one day applied as lagged variables to the following day, essentially as one would intuitively expect.

Usage

1
esm_day_lag(data, variables, person_id, day_id)

Arguments

data

The dataset to operate on.

variables

The character vector of variables to lag

person_id

The person level grouping variable - this should be your person id variable.

day_id

The day level grouping variable - this should be your day id variable.

Details

Note that this function works with long data (i.e. expects one row per beep) though it may work with different formats, I wouldn't guarantee it. Could technically be used to lag observation level variables if you added the beep id to the grouping vector, but no reason to use it in that fashion and I haven't tested it.

esm_lag and esm_day_lag are unique in that they output variables with the same appelation (_lag) because they output what we would expect for lag at each level so this intuitively makes sense. The variables will already have names to say whether they're at the day level or not.


seanchrismurphy/emacalc documentation built on May 12, 2019, 2:03 p.m.