I have two vectors like this:
vec1<-c(0, 0, 1, 1, 0, 0, 0, 0, 0, 0)
vec2<-c(0, 0, 0, 1, 0, 0, 1, 0, 1, 0)
I want to merge it somehow to turn it into this:
vec<-c(0, 0, 1, 1, 0, 0, 1, 0, 1, 0)
Is there any way to do this?
CodePudding user response:
We can use pmax
pmax(vec1, vec2)
[1] 0 0 1 1 0 0 1 0 1 0
or with |
(vec1|vec2)
CodePudding user response:
Here is a solution with ifelse
:
ifelse(vec1==0 & vec2==0, 0, 1)
[1] 0 0 1 1 0 0 1 0 1 0