I have two vectors:
a<-rep(1:2,100) b<-sample(a)
I would like to have an ifelse condition that compares each value of a
a
This is an easy way:
(a > b) + (a == b) * sample(2, length(a), replace = TRUE)
This is based on calculations with boolean values which are cast into numerical values.