It is quite surprise to me that I could not find a ready answer for this question on stackoverflow.
In R, I have a vector of 0 and 1, and I wan
0
1
We can use !!:
!!
rep(0:1, 5) [1] 0 1 0 1 0 1 0 1 0 1 !!rep(0:1, 5) [1] FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
All 0s will be converted to FALSE, any other numeric to TRUE.
FALSE
TRUE