Re: [R] R Newbie, please help!

From: Jeff08 <jefferyding_at_gmail.com>
Date: Thu, 03 Jun 2010 22:20:57 -0700 (PDT)

Hey Josh,

Thanks for the quick response!

I guess I have to switch from the Java mindset to the matrix/vector mindset of R.

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.

>>"Hello Jeff,

Try 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.

______________________________________________
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.
Received on Fri 04 Jun 2010 - 05:54:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Jun 2010 - 06:50:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive