dummy variables dependent on two other variables

Hello everyone!

i am struggling a bit with the following issue:

I want to create a dummy variable that takes the value 1 if either variable a has a value between 300 and 400 or if value b has a value 1. Only one of these would need to be fulfilled, I.e. variable a could be outside the range, but b=1, the dummy would still be 1. Is there any way to compute this? I can't find any way (even in the fast dummies package, to my understanding) to incorporate both of these.

Maybe
d <- ifelse( (a>=300 & a<=400) | b == 1, 1 , 0)

thank you so much, that was it! didn't realise I could use the | sign like that

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.