[R] R Newbie, please help!

Jeff08 jefferyding at gmail.com
Fri Jun 4 05:04:07 CEST 2010


Hello Everyone,

I just started a new job & it requires heavy use of R to analyze datasets.

I have a data.table that looks like this. It is sorted by ID & Date, there
are about 150 different IDs & the dataset spans 3 million rows. The main
columns of concern are ID, date, and totret. What I need to do is to derive
daily returns for each ID from totret, which is simply totret at time t+1
divided by totret at time t. 

              X       id ticker      date_ adjClose    totret RankStk
427225   427225 00174410    AHS 2001-11-13    21.66 100.00000    1235
441910   441910 00174410    AHS 2001-11-14    21.60  99.72300    1235
458458   458458 00174410    AHS 2001-11-15    21.65  99.95380    1235
284003   284003 00174410    AHS 2001-11-16    21.59  99.67680    1235

Two problems for me:

1)I can't just apply it to the entire column since there will be problems at
the boundary points where the ID changes from 1 to another. I need to find
out how to specify a restriction on the name of the ID

2) From Java, instinctively I would use a loop to calculate daily returns,
but I found out that R is very slow with loops, so I need to find an
efficient way to calculate  daily returns with such a huge dataset.

Thanks a lot!


-- 
View this message in context: http://r.789695.n4.nabble.com/R-Newbie-please-help-tp2242633p2242633.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list