Thanks. It works! I think I found another solution, working straight with the indicator matrix. > count <- factor(table(apply(ind, 1, paste, collapse=""))) However, that way I can't store the indices of the collapsed rows. -Angelos Markos