On 3 July 2012 22:03, Akhil dua <akhil.dua.12@gmail.com> wrote:
> and I need to run a seperate regression of every stock on market
> so I want to write a "for loop" so that I wont have to write
codes again
> and again to run the regression...
>
1. Do give a subject line -- a blank one is commonly used by a virus.
2. In R/S+/most functional languages, you do not want to write a "for
loop". Use apply (and friends) instead.
> my data is in the format given below
>
> Date Stock1 Stock2 Stock3 Market
> 01/01/2000 1 2 3 4
> 01/02/2000 5 6 7 8
> 01/03/2000 1 2 3 4
> 01/04/2000 5 6 7 8
>
For example, if you wanted to know the stocks share of the total market as
a fraction, you'd use something like:
sapply(myData[,c(2:4)], function(x) {
return(as.numeric(x)/as.numeric(myData[,4])) })
Hope that helps.. -- H
--
Sent from my mobile device
Envoyait de mon portable
[[alternative HTML version deleted]]