-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlagw.R
More file actions
27 lines (27 loc) · 695 Bytes
/
Copy pathlagw.R
File metadata and controls
27 lines (27 loc) · 695 Bytes
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
function (x, k, initial = NULL)
{
n = length(x)
lagk = NULL
k = as.integer(k)
if (k < 0) {
stop("'k' must be a non negative integer value!\n")
}
else {
if (is.null(initial)) {
for (i in 0:k) {
lagk = cbind(lagk, x[(k + 1 - i):(n - i)])
}
}
else {
stopifnot(length(initial) == k)
i = 1
lagk = as.matrix(x)
while (i <= k) {
lagk = cbind(lagk, c(initial[1:i], x[1:(n - i)]))
i = i + 1
}
}
}
colnames(lagk) = paste("lag", 0:k, sep = "")
return(as.matrix(lagk))
}