I prefer the idiom c(TRUE, a[-1] != a[-length(x)]) because it works for character and other data types as well. I also find that thinking in terms of runs instead of subscripting tricks is easier.