Reputation: 22270
I want to apply logical NOT
to the specified indexes of a binary integer vector.
Example: given c(0, 1, 0)
and c(1, 3)
, I want to obtain c(1, 1, 1)
.
What's a vectorized way to do this?
Upvotes: 0
Views: 49
Reputation: 37641
x = c(0, 1, 0)
Changes = c(1, 3)
x[Changes] = !x[Changes]
x
[1] 1 1 1
Upvotes: 1