Re: [R] without the loop

From: Giovanni Petris <GPetris_at_uark.edu>
Date: Sat 14 May 2005 - 07:51:47 EST

I won't go into the details of your loop, but in general it is usually better, if possible, to create a list of the appropriate length upfront.

Giovanni

> Date: Fri, 13 May 2005 16:58:42 -0400
> From: Omar Lakkis <uofiowa@gmail.com>
> Sender: r-help-bounces@stat.math.ethz.ch
> Precedence: list
> DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
>
> Can this be re-implemented to run faster (without the loop) ?
>
> r <- list()
> n = nrow(prices)
> for (i in (w+1):n) {
> window <- prices[(i-w):(i-1),]
> if (prices[i,]$settle > max(window$high)) r <-
> append(r, 1)
> else if (prices[i,]$settle < min(window$low)) r <-
> append(r, -1)
> }
>
> ______________________________________________
> 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
>
>

-- 

 __________________________________________________
[                                                  ]
[ Giovanni Petris                 GPetris@uark.edu ]
[ Department of Mathematical Sciences              ]
[ University of Arkansas - Fayetteville, AR 72701  ]
[ Ph: (479) 575-6324, 575-8630 (fax)               ]
[ http://definetti.uark.edu/~gpetris/              ]
[__________________________________________________]

______________________________________________
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
Received on Sat May 14 07:56:34 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:45 EST