File: Lag.Rd

package info (click to toggle)
hmisc 4.2-0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 3,332 kB
  • sloc: asm: 27,116; fortran: 606; ansic: 411; xml: 160; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 828 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
\name{Lag}
\alias{Lag}
\title{Lag a Numeric, Character, or Factor Vector}
\description{
Shifts a vector \code{shift} elements later.  Character or factor
variables are padded with \code{""}, numerics with \code{NA}.  The shift
may be negative.
}
\usage{
Lag(x, shift = 1)
}
\arguments{
  \item{x}{a vector}
  \item{shift}{integer specifying the number of observations to
	be shifted to the right.  Negative values imply shifts to the left.}
}
\details{
A.ttributes of the original object are carried along to the new lagged
one.
}
\value{
a vector like \code{x}
}
\author{Frank Harrell}
\seealso{\code{\link{lag}}}
\examples{
Lag(1:5,2)
Lag(letters[1:4],2)
Lag(factor(letters[1:4]),-2)
# Find which observations are the first for a given subject
id <- c('a','a','b','b','b','c')
id != Lag(id)
!duplicated(id)
}
\keyword{manip}