Skip to content
Prev 132676 / 398506 Next

number of count of each unique row

Hi Louis,

If I am understanding your question correctly, here is one way:
suppose your matrix is M of dimension n x k.

D <- data.frame(M)  # convert to data frame
ones <- rep(1, n)   # a column of 1s

Now you can count the number of repeats of each unique row.

aggregate( ones, by = as.list(D), FUN = sum)

The output will be a data frame with the unique rows, and a column at
the end labeled "x" with the frequency of each unique row.

Once you get this you can convert to a list, manipulate, etc.  I am
sure that there exist faster/better methods.

Best,
Jay
On Dec 21, 2007 5:03 PM, Louis Martin <louismartinbis at yahoo.fr> wrote: