which(!!diff(as.numeric(x)))
[1] 3 5 6
It is assumed that you really have factors. They are stored internally with numerical values. Therefore, when a difference is made, each will take place with every change. The second coercion is that zeros are considered FALSE and other TRUE numbers. whichfinds the TRUE values of aka non-zeroes.
source
share