flip certain bits in vector
jim holtman wrote:
try this:
b <- c(1, 0, 1, 0, 1, 0, 1, 0, 1, 0) p <- c(1, 3, 5, 7) b[p] <- ifelse(b[p] == 0, 1, 0)
I'll have to look up the ifelse operator, looks like the ternary operator used in C b[p] = b[p]==0?1:0 Cool - thanks! Esmail