Reputation: 25
I need to create a dummy variable where if 20≤dummy≤40, it reads '1', and '0' otherwise. I think I am having a brainfart, but I cannot seem to do it.
I currently have:
dummy_x <- ifelse(x<=40, 1, 0)
which works, however:
dummy_x <-ifelse(20<=x<=40, 1, 0)
does not. If anyone can help, it would be greatly appreciated.
Upvotes: 1
Views: 1125
Reputation: 1329
You have to split the second ifelse
into two conditions like ifelse(x>=20 & x <=40, 1, 0)
Upvotes: 1