R/grouplag.R

Defines functions lag grouplag

grouplag <- function(x,gr,varnum=NULL) {
result <- by(x,gr,lag,varnum)
return(result)
}

lag <- function(x,varnum) {if(!is.null(varnum))  x <- x[-varnum]
cname <- colnames(x)
results <- cbind(x, x[row(x[,1,drop=FALSE])+1,])
colnames(results) <- c(cname,paste(cname,2,sep=""))
return(results)
}

Try the psych package in your browser

Any scripts or data that you put into this service are public.

psych documentation built on June 27, 2024, 5:07 p.m.