[R] how to calculate the return?
Scionforbai
scionforbai at gmail.com
Sat Nov 24 15:39:56 CET 2007
Hi Denver,
> I want to calculate the return say AMR,so I use
If data is a matrix or a data.frame you need to use the correct
index: [row,col] instead of [row]. Try:
re=numeric(10)
for (i in 2:nrow(data)) {
re[1]=0
re[i]=log(data[i,1]/data[i-1,1])
}
This works, but of course you have negative values of the ratio, so
the log cannot be computed.
See also ?apply.
More information about the R-help
mailing list