I think this is what you are looking for.

> tmp <- matrix(sample(20), 5, 4)
> tmp
     [,1] [,2] [,3] [,4]
[1,]    6   15   18   20
[2,]    4    5   10   19
[3,]    7    9    1    3
[4,]    8   14   11   13
[5,]   17   12   16    2
> t(apply(tmp, 1, diff))
     [,1] [,2] [,3]
[1,]    9    3    2
[2,]    1    5    9
[3,]    2   -8    2
[4,]    6   -3    2
[5,]   -5    4  -14
>



On Mon, Dec 17, 2012 at 12:16 PM, kevj1980 <kevin.kidney@cameronhume.com>wrote:

> Hi, I have an n x m matrix of numerical observations. ie. stock prices
>
> I wish to convert the matrix of observations to a matrix of simple returns
> (by taking the differences between (column) observations.)
>
> Can any good soul suggest a function for this?
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/R-beginner-matrix-algebra-tp4653335.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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]]


