Re: [R] matrix of higher order differences

2011-04-27 Thread Ravi Varadhan
: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 gmail.com>

Re: [R] matrix of higher order differences

2011-04-27 Thread peter dalgaard
ject.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 gmail.com> writes: >&

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 gmail.com> writes: > &g

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 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 sec

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 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

Re: [R] matrix of higher order differences

2011-04-27 Thread Hans W Borchers
Jeroen Ooms 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 <- function(x

[R] matrix of higher order differences

2011-04-26 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);