[R] R Newbie, please help!
jefferyding at gmail.com
Fri Jun 4 07:20:57 CEST 2010
Thanks for the quick response!
I guess I have to switch from the Java mindset to the matrix/vector mindset
Your code worked very well, but I just have one problem:
Essentially I have a time series of stock A, followed by a time series of
stock B, etc.
So there are break points in the data (the points where it switches stocks
have incorrect returns, and should be NA at t=0 for each stock)
Is there an easy way to account for this in R? What I was thinking of is if
there is a way to make a filter rule. Such as if the ID of the row matches
Stock A, then perform this.
test <- data.frame(totret=rnorm(10^7)) #create some sample data
test[-1,"dailyreturn"] <- test[-1,"totret"]/test[-nrow(test),"totret"]
The general idea is to take the column "totret" excluding the first 1,
dividided by "totret" exluding the last row. This gives in effect t+1
(since t is now shorter)/t
I assigned the result to a new column "dailyreturn". For 10^7 rows,
it tooks 1.92 seconds on my system."
View this message in context: http://r.789695.n4.nabble.com/R-Newbie-please-help-tp2242633p2242703.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help