[R] flip certain bits in vector

Esmail esmail.js at gmail.com
Sun Apr 19 21:59:50 CEST 2009


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



More information about the R-help mailing list