On Mon, May 18, 2009 at 6:00 PM, Gabor Grothendieck <ggrothendieck@gmail.com
> wrote:

> I understood what you were asking but R is an oo language so
> that's the model to use to do this sort of thing.
>

I am not talking about creating a new class with an analogue to the
subtraction function.  I am talking about a function which applies another
function to a sequence and its lagged version.

Functional arguments are used all over the place in R's base package
(Xapply, sweep, outer, by, not to mention Map,  Reduce, Filter, etc.) and
they seem perfectly natural here.

Or perhaps I am not understanding your objection.

              -s


> On Mon, May 18, 2009 at 5:48 PM, Stavros Macrakis <macrakis@alum.mit.edu>
> wrote:
> > I guess I wasn't very clear.  The goal is not to define diff on a
> different
> > object type, but to have a different 'subtraction' operator with the same
> > lag logic.  An easy example would be quotient instead of subtraction. Of
> > course I could do that by simply cutting and pasting diff.default and
> > replacing '-'(a,b) with f(a,b), but it's cleaner to use a standard
> function
> > if there is one.
> >
> >           -s
> >
> > On Mon, May 18, 2009 at 5:05 PM, Gabor Grothendieck
> > <ggrothendieck@gmail.com> wrote:
> >>
> >> You can define a new class for the object diff operates
> >> on and then define your own diff method for that. For
> >> some examples see:
> >>
> >> methods(diff)
> >>
> >>
> >>
> >> On Mon, May 18, 2009 at 4:24 PM, Stavros Macrakis <
> macrakis@alum.mit.edu>
> >> wrote:
> >> > I would like to apply a function 'f' to the lagged version of a vector
> >> > and
> >> > the vector itself.
> >> >
> >> > This is easy to do explicitly:
> >> >
> >> >      mapply( f, v[-1], v[-length(v)] )
> >> >
> >> > or in the case of a pointwise vector function, simply
> >> >
> >> >      f( v[-1], v[-length(v)] )
> >> >
> >> > This is essentially the same as 'diff' but with an arbitrary function,
> >> > not
> >> > '-'.
> >> >
> >> > Is there a standard way to do this? Is there any particular reason
> that
> >> > 'diff' should not have an 'f' argument?
> >> >
> >> >            -s
> >> >
> >> >        [[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]]


