This is admittedly a contrived example, but... data(housing, package ="MASS") x <- housing$Type + housing$Sat match(x, unique(x)) Hadley -- http://had.co.nz/