[R] flip certain bits in vector

Esmail esmail.js at gmail.com
Sun Apr 19 21:58:00 CEST 2009


David Winsemius wrote:
> I do not think your wetware processed the inputs correctly. The second 
> bit should not have been flipped:

Ooops .. yes you are right!

> 
> Try this loop free index based solution:
> 
>  b <- c( 1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
>  r <- b
>  r[p] <- 0 + !r[p]  # adding 0 converts logical TRUE/FALSE  to 0/1
>  r
>  [1] 0 0 0 0 0 0 0 0 1 0

Great! .. thanks ... I appreciate the hlep,


Esmail




More information about the R-help mailing list