On 2011-01-17 07:44, eric wrote:

What am I doing wrong here ? And what's the right way to calculate the log
differences in a column in a df ?

# first 3 rows of 5000 rows
y[1:3,]

  Date  Open  High   Low Close
1 1983-03-30 29.96 30.51 29.96 30.35
2 1983-03-31 30.35 30.55 30.20 30.24
3 1983-04-04 30.25 30.65 30.24 30.39

#equation in question ...why is this giving zeros ?
y1<- 100*log(y[,5]/(lag(y[,5],1)))

# first 10 values from the equation...all zeros
head(y1,10)
  [1] 0 0 0 0 0 0 0 0 0 0

Well, take a look at the output of lag().
Try it with as.ts(y[, 5]) replacing y[, 5].

Peter Ehlers

______________________________________________
R-help@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.

Reply via email to