search for: cumnox

Displaying 1 result from an estimated 1 matches for "cumnox".

Did you mean: cubox
2007 Nov 20
1
Vectorization/Speed Problem
...a for()! Here is my shot at a vectorized solution, as far as I can take it. Preliminary Vectorized Code: X <- matrix(sample(c(1,0,0,0,0), 500, replace = TRUE), 25, 20, byrow=TRUE) colnames(X) <- c(paste("a", 1:20, sep="")) noX <- X; noX[X!=0] <- 0; cumX <- noX; cumNoX <- noX; Y1 <- noX; Y2 <- X; Y3 <- X for (e in 1:ncol(X)) { cumX[,e] <- cumsum(X[,e]) noX[X[,e] < 1 & cumsum(X[,e]) > 0 ,e] <- 1 cumNoX[,e] <- cumsum(noX[,e]) } Y1[cumNoX > 0] <- cumNoX[cumNoX > 0] + 1 Y2[X == 0 & noX > 0] <- Y1[X == 0 & noX...