[R] duplicated rows of a matrix

William Dunlap wdunlap at tibco.com
Mon Jul 21 21:17:24 CEST 2014


Can you give an example of duplicated() not working on the rows of a matrix?

Here is an example where it does work:
> m <- cbind(c(a=1,b=2,c=3,d=2,e=3,f=4,g=1,h=1), c(11,13,11,13,11,13,13,11))
> class(m)
[1] "matrix"
> m
  [,1] [,2]
a    1   11
b    2   13
c    3   11
d    2   13
e    3   11
f    4   13
g    1   13
h    1   11
> duplicated(m)
[1] FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE  TRUE
> m[duplicated(m), ]
  [,1] [,2]
d    2   13
e    3   11
h    1   11

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 21, 2014 at 7:54 AM, carol white <wht_crl at yahoo.com> wrote:
> Hi,
> is it possible to find the duplicated rows of a matrix without a loop or i have to loop over the rows? duplicated doesn't seem to be helpful
>
> Thanks
>
> Carol
>
>         [[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.



More information about the R-help mailing list