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.
______________________________________________
[email protected] 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.