Skip to content
Prev 247711 / 398506 Next

Log difference in a dataframe column

lag and as.ts are separate operations (which in fact commute)
Time Series:
Start = 0 
End = 9 
Frequency = 1 
 [1]  1  2  3  4  5  6  7  8  9 10
Time Series:
Start = 0 
End = 9 
Frequency = 1 
 [1]  1  2  3  4  5  6  7  8  9 10
You do NOT need to call as.ts at all it that's your bent:
[1]  1  2  3  4  5  6  7  8  9 10
attr(,"tsp")
[1] 0 9 1

but as lag is an operation designed for time series objects, it's a pretty good bet that to make any sense of the result you need to start (or end up) with a time series object.

The key is the concept of an 'object' in R.  You need to know what kind of objects you are dealing with.
 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of eric
Sent: Wednesday, 19 January 2011 1:08 PM
To: r-help at r-project.org
Subject: Re: [R] Log difference in a dataframe column


Just learning so excuse me if I'm being too basic here. But I'm wondering how
should I know that as.ts would be needed for lag ? Is there a thought
process or way to inspect that I should have gone through to know that log
would work on y[,5] but lag would not work on [,5] ? 

Is the general rule that lag is not in the base package and therefore would
not work ?

Thanks for the comments