[R] matrix of higher order differences

2011-04-27 Thread Jeroen Ooms
Is there an easy way to turn a vector of length n into an n by n matrix, in which the diagonal equals the vector, the first off diagonal equals the first order differences, the second... etc. I.e. to do this more efficiently: diffmatrix - function(x){ n - length(x); M - diag(x);

Re: [R] matrix of higher order differences

2011-04-27 Thread Hans W Borchers
Jeroen Ooms jeroenooms at gmail.com writes: Is there an easy way to turn a vector of length n into an n by n matrix, in which the diagonal equals the vector, the first off diagonal equals the first order differences, the second... etc. I.e. to do this more efficiently: diffmatrix -

Re: [R] matrix of higher order differences

2011-04-27 Thread David Winsemius
On Apr 27, 2011, at 7:25 AM, Hans W Borchers wrote: Jeroen Ooms jeroenooms at gmail.com writes: Is there an easy way to turn a vector of length n into an n by n matrix, in which the diagonal equals the vector, the first off diagonal equals the first order differences, the second...

Re: [R] matrix of higher order differences

2011-04-27 Thread Petr Savicky
On Wed, Apr 27, 2011 at 11:25:42AM +, Hans W Borchers wrote: Jeroen Ooms jeroenooms at gmail.com writes: Is there an easy way to turn a vector of length n into an n by n matrix, in which the diagonal equals the vector, the first off diagonal equals the first order differences, the

Re: [R] matrix of higher order differences

2011-04-27 Thread Ravi Varadhan
-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Petr Savicky Sent: Wednesday, April 27, 2011 11:01 AM To: r-help@r-project.org Subject: Re: [R] matrix of higher order differences On Wed, Apr 27, 2011 at 11:25:42AM +, Hans W Borchers wrote: Jeroen Ooms jeroenooms at gmail.com writes

Re: [R] matrix of higher order differences

2011-04-27 Thread peter dalgaard
@r-project.org Subject: Re: [R] matrix of higher order differences On Wed, Apr 27, 2011 at 11:25:42AM +, Hans W Borchers wrote: Jeroen Ooms jeroenooms at gmail.com writes: Is there an easy way to turn a vector of length n into an n by n matrix, in which the diagonal equals the vector

Re: [R] matrix of higher order differences

2011-04-27 Thread Ravi Varadhan
AM To: r-help@r-project.org Subject: Re: [R] matrix of higher order differences On Wed, Apr 27, 2011 at 11:25:42AM +, Hans W Borchers wrote: Jeroen Ooms jeroenooms at gmail.com writes: Is there an easy way to turn a vector of length n into an n by n matrix, in which the diagonal