Hi John,
dplyr::lag expects a vector. The following should work
dplyr::lag(temp[,1],2)
HTH,
Eric
On Mon, Mar 25, 2019 at 9:45 AM John wrote:
> Hi,
>
>I have a dataset whose row names corresponds to months. When I apply lag
> function (dplyr package) on this dataset, I get NAs with warning
Hi,
I have a dataset whose row names corresponds to months. When I apply lag
function (dplyr package) on this dataset, I get NAs with warning messages.
Is there any lag function that carries out the lag but keep the row names?
I will have two datasets. The dates of the datasets are not exact
Well, maybe. Whether it's +24 or -24 depends on what you mean by "one day
lag." I suspect you mean -24, but perhaps this will help you decide:
test <- ts(1:72, frequency = 24)
plot(lag(test,24))
plot(lag(test,-24))
Note that the +24 moves the time base back 24 observable units (= hours)
and -24 m
I have an hourly database and I defined a variable as follows:
time<-ts(data$variable, frequency=24)
If i need to create the variables with one day lag, the corresponding
command is lag(time,24)?
Thank you
[[alternative HTML version deleted]]
It seems to mean that it adds a Tsp attribute but it does not change
the class to "ts":
> dput(lag(1:3))
structure(1:3, .Tsp = c(0, 2, 1))
Try this:
> ts(1:3) - structure(lag(1:3), class = "ts")
Time Series:
Start = 1
End = 2
Frequency = 1
[1] -1 -1
or
> ts(1:3) - lag(ts(1:3))
Time Series:
Sta
Hello,
Downey, Patrick wrote:
Can anyone tell me what's going on here?
x <- matrix(data=c(1,2,3,4,5),ncol=1)
x1 <- lag(x,k=1)
x
x1
x - x1
That's with x specified as a column vector, but the same thing happens when
it's a row vector.
x <- c(1,2,3,4,5)
x1 <- lag(x,k=1)
x
x1
x - x1
I'm not su
Can anyone tell me what's going on here?
x <- matrix(data=c(1,2,3,4,5),ncol=1)
x1 <- lag(x,k=1)
x
x1
x - x1
That's with x specified as a column vector, but the same thing happens when
it's a row vector.
x <- c(1,2,3,4,5)
x1 <- lag(x,k=1)
x
x1
x - x1
When the documentation says "Vector or matrix
Note that there is actually a good reason why this is so.
ts can only represent regularly spaced series but the
result of a subscripting operation might not be a regularly
spaced series so you would not be able to guarantee that
it could be a ts series as well. That's the reason for window.ts
too
thanks. i'll try zoo or xts. ts is a p.i.t.a.
Gabor Grothendieck wrote:
>
> lag1resid is a time series, try
>
> str(residsq)
> str(lag1residsq)
>
> The problem is that when you subscript lag1resid you
> don't get a time series out from that. See ?window.ts
> or try the zoo or xts packages
lag1resid is a time series, try
str(residsq)
str(lag1residsq)
The problem is that when you subscript lag1resid you
don't get a time series out from that. See ?window.ts
or try the zoo or xts packages where subscripting of time
series works.
On Fri, Oct 10, 2008 at 1:27 PM, Scotty Nelson <[EMAIL
I am trying to lag a time series. My data is in a matrix, but I coerce it
into a ts object.
But when I lag it and then look at the result, nothing has changed. What am
I doing wrong?
residsq<-resid^2
residsq<-as.ts(residsq)
lag1residsq<-lag(residsq,-1)
> residsq[1:5]
1
11 matches
Mail list logo