Re: [R] How to optimize this loop ? (correction)

From: Martin Becker <martin.becker_at_mx.uni-saarland.de>
Date: Thu 18 Jan 2007 - 14:22:07 GMT

Sorry, I accidentaly lost one line of the function code (result <-0), see below...
Regards, Martin

Martin Becker schrieb:
>
> myfun1 <- function(series=c(3, 4, 10,14,8,3,4,6,9)) {

     result <- 0                        # NEW

> len<-length(series)
> for (i in (len-1):1)
> {
> if (series[i]>series[len])
> { result <- i-1 ; break }
> }
> return(result)
> }
>
...

R-help@stat.math.ethz.ch 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 Fri Jan 19 01:33:40 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 19 Jan 2007 - 03:30:27 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.