Re: [R] number of count of each unique row

From: Benilton Carvalho <bcarvalh_at_jhsph.edu>
Date: Sun, 23 Dec 2007 05:04:48 -0500

i didn't test, but i think you want something like:

table(apply(x, 1, paste, collapse=","))

where "x" is your matrix...

b

On Dec 23, 2007, at 5:01 AM, Jim Lemon wrote:

> Louis Martin 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.
>>
> Hi Louis,
> If you want the unique rows returned, this might do the job.
>
> unique.rows<-function(x) {
> nrows<-dim(x)[1]
> urows<-1:nrows
> for(i in 1:(nrows-1)) {
> for(j in (i+1):nrows) {
> if(!is.na(urows[j])) if(all(x[i,]==x[j,])) urows[j]<-NA
> }
> }
> return(x[urows[!is.na(urows)],])
> }
>
> Jim
>
> ______________________________________________
> 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.



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. Received on Sun 23 Dec 2007 - 10:09:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 23 Dec 2007 - 14:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.