Re: [R] any alternatives for complex for-loops?

From: Ray Brownrigg <Ray.Brownrigg_at_mcs.vuw.ac.nz>
Date: Wed, 12 Nov 2008 17:05:08 +1300

Well, there is an implicit for loop, expressed by:

x[i] = complexFn(x[i-1], x[i-2])

But my response is along the lines of:

It really depends what your "..." is.

How about something like (pseudo-code again):

x[1] <- something
x[2] <- something_else

x = complexFn(x)

so the vectorisation is taken care of inside complexFn.

Ray Brownrigg

On Wed, 12 Nov 2008, hadley wickham wrote:
> On Tue, Nov 11, 2008 at 8:30 PM, Kinoko <andzsinszan@gmail.com> wrote:
> > Dear list,
> >
> > Is there a way to do something like the following pseudo-code -
> > without for loop?
>
> There isn't a for loop in your code!
>
> Hadley
>
> > complexFn <- function(a,b){
> > ...
> > return(c)
> > }
> >
> > x[i] = complexFn(x[i-1], x[i-2])
> >
> >
> > I have found "filter" but would like to do something more complicated
> > than multiplication with x[i-1] and x[i-2].
> >
> > Thanks in advance!
> >
> > gabor
> >



R-help_at_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. Received on Wed 12 Nov 2008 - 04:09:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 12 Nov 2008 - 06:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive