[R] Log difference in a dataframe column

Bill.Venables at csiro.au Bill.Venables at csiro.au
Wed Jan 19 04:49:04 CET 2011


lag and as.ts are separate operations (which in fact commute)

> lag(as.ts(1:10), 1)
Time Series:
Start = 0 
End = 9 
Frequency = 1 
 [1]  1  2  3  4  5  6  7  8  9 10

> as.ts(lag(1:10, 1))
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:

> lag(1:10, 1)
 [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

-- 
View this message in context: http://r.789695.n4.nabble.com/Log-difference-in-a-dataframe-column-tp3221225p3224478.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list