foo <- matrix(c(1,2,3,
                2,3,4,
                1,2,3,
                4,5,6), byrow=TRUE, ncol=3)
multiplicity(foo)
# the following function determines the multiplicity of rows of a
# numeric matrix and returns unique rows with appended multiplicity
countunique <- function (matrix) {
    count <- multiplicity(matrix)
    unique(cbind(matrix, count))
}
countunique(foo)Run the code above in your browser using DataLab