Re: [R] lag function row name with

2019-03-25 Thread Eric Berger
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

Re: [R] Lag function

2018-08-07 Thread Bert Gunter
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

Re: [R] Lag Function

2010-03-22 Thread Gabor Grothendieck
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

Re: [R] Lag Function

2010-03-22 Thread Erik Iverson
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

Re: [R] lag function doesn't work - what am i doing wrong?

2008-10-10 Thread Gabor Grothendieck
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

Re: [R] lag function doesn't work - what am i doing wrong?

2008-10-10 Thread Scotty Nelson
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

Re: [R] lag function doesn't work - what am i doing wrong?

2008-10-10 Thread Gabor Grothendieck
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