[R] Log difference in a dataframe column

eric ericstrom at aol.com
Mon Jan 17 16:44:07 CET 2011


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
-- 
View this message in context: http://r.789695.n4.nabble.com/Log-difference-in-a-dataframe-column-tp3221225p3221225.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list