Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

lags.fnc

Calculate vector at specified lag


Description

This function calculates for a given dependent variable the value of that variable at lag timesteps earlier in the time series of an experiment.

Usage

lags.fnc(dat, time="Trial", group = "Subject", depvar = "RT", lag=1)

Arguments

dat

A data frame with (minimally) a grouping factor, an time index for successive trails/events, and a behavioral measure

group

A grouping factor such as Subject

time

A sequential time index measure such as Trial number in an experimental list

depvar

The dependent variable, usually a chronometric measure such as RT

lag

The lag for which previous values are to be extracted

Value

A vector with the values of the dependent variable at the specified lag. The by-group mean is substituted for the first lag timestep(s), for which there is/are no preceding value(s) for the dependent variable.

Author(s)

R. H. Baayen

See Also

Examples

## Not run: 
  dfr = data.frame(Subject=c(rep("a", 5), rep("b", 5)),
                   Trial = c(rep(1:5,2)),
                   RT = rnorm(10, 500, 40))
  dfr$prevRT = lag.fnc(dfr, time="Trial", group="Subject", depvar="RT")
  dfr


## End(Not run)

languageR

Analyzing Linguistic Data: A Practical Introduction to Statistics

v1.5.0
GPL (>= 2)
Authors
R. H. Baayen <harald.baayen@uni-tuebingen.de>, Elnaz Shafaei-Bajestan <elnaz.shafaei-bajestan@uni-tuebingen.de>
Initial release
2019-01-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.