Reputation: 119
I have one vector, example x=c(0,0,0,1,1,2,3,4,5,6)
.
I want write out all zeros, all ones and next all numbers divisible by 2.
The output would look like this: 0 0 0 1 1 2 4 6
I don't know how to write out zeros and ones, because next I use (which (x %% 2==0))
. Can anyone help?
Upvotes: 1
Views: 68
Reputation: 887118
We can try with %%
and use |
x[x%%2==0 | x==1]
#[1] 0 0 0 1 1 2 4 6
Upvotes: 3