[R] How to get rid of loop?

bartjoosen bartjoosen at hotmail.com
Tue Apr 28 11:25:32 CEST 2009


Hi,

how about this:
x <- runif(100) 
n <- length( x ) 

y2 <- rep(0,n)
y2[x > 0.75] <- 1
y2[x < 0.25] <- -1
cx <- cumsum(abs(y2) )
m <- match(cx, cx)
y2[y2==0] <- 2
y2[x<0.5 & y2[m]==1] <- 0
y2[x>0.5 & y2[m]==-1] <- 0
y3 <- y2
y3[y3==0] <- 1
y3[y3==2] <- 0
cx <- cumsum(abs(y3))
m <- match(cx, cx)
y2 <- y2[m]


Best regards

Bart
-- 
View this message in context: http://www.nabble.com/How-to-get-rid-of-loop--tp23226779p23273405.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list