Re: [R] difference along a vector

2010-05-12 Thread Henrique Dallazuanna
Try this: n <- 3 apply(embed(a, n + 1)[,c(1, n + 1)], 1, diff) On Wed, May 12, 2010 at 4:06 PM, Clark Johnston wrote: > > I was looking for a function which would take the difference along a > vector? > >a<-c(1,12,23,44,15,28,7,8,9,10) > if I set the number difference to 3 would return > 43 > 2

Re: [R] difference along a vector

2010-05-12 Thread Marc Schwartz
On May 12, 2010, at 2:06 PM, Clark Johnston wrote: > > I was looking for a function which would take the difference along a vector? >> a<-c(1,12,23,44,15,28,7,8,9,10) > if I set the number difference to 3 would return > 43 > 2 > 5 > -37 > -7 > -19 > 3 > > or do I need to write my own function f

Re: [R] difference along a vector

2010-05-12 Thread Erik Iverson
help.search("difference") would lead you to ?diff, see the lag argument Clark Johnston wrote: I was looking for a function which would take the difference along a vector? a<-c(1,12,23,44,15,28,7,8,9,10) if I set the number difference to 3 would return 43 2 5 -37 -7 -19 3 or do I need to wr

Re: [R] difference along a vector

2010-05-12 Thread Peter Ehlers
?diff and look at argument 'lag'. On 2010-05-12 13:06, Clark Johnston wrote: I was looking for a function which would take the difference along a vector? a<-c(1,12,23,44,15,28,7,8,9,10) if I set the number difference to 3 would return 43 2 5 -37 -7 -19 3 or do I need to write my own functio

[R] difference along a vector

2010-05-12 Thread Clark Johnston
I was looking for a function which would take the difference along a vector? >a<-c(1,12,23,44,15,28,7,8,9,10) if I set the number difference to 3 would return 43 2 5 -37 -7 -19 3 or do I need to write my own function for this. -- View this message in context: http://r.789695.n4.nabble.com/diff