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:> Hi,
>
> I have a matrix of duplicate rows. How to output a list the unique rows
with their count? I have used "unique" to have the unique rows, but
can't produce the occurences of each unique row.
>
> Thanks
>
> Louis
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
***************************************************
G. Jay Kerns, Ph.D.
Assistant Professor / Statistics Coordinator
Department of Mathematics & Statistics
Youngstown State University
Youngstown, OH 44555-0002 USA
Office: 1035 Cushwa Hall
Phone: (330) 941-3310 Office (voice mail)
-3302 Department
-3170 FAX
E-mail: gkerns at ysu.edu
http://www.cc.ysu.edu/~gjkerns/