0

I have two vectors that I need to add together, but only in instances where their corresponding values are not equal. Ex:

aa <- c(1,0,0,1,0)
bb <- c(0,1,1,1,0)

I want to generate a combined vector like so:

aa <- c(1,1,1,1,0)

How might I go about doing this, particularly with vectorization?

Kaddy
  • 13
  • 5

1 Answers1

1

Looks like you are trying to implement the OR gate .You can use pmax :

pmax(aa, bb)
#[1] 1 1 1 1 0
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213