Perhaps something along the lines of (untested) t(apply(yourdata[, -1], 2, function(x) diff(log(x))))
is what you are looking for. See ?apply, ?diff and ?t for more information. HTH, Jorge.- On Thu, Jul 5, 2012 at 12:58 AM, Akhil dua <> wrote: > Hello Every one > I have data on Stock prices and I want to calculate the return on all the > stocks > and then replace all the stock prices with the returns > > can any one tell me how to do > > My data is in the format given below > > Date Stock1 Stock2 Stock3 > 01/01/2000 1 2 3 > 01/02/2000 5 6 7 > 01/03/2000 1 2 3 > 01/04/2000 5 6 7 > > > Thanks > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.