duplicated(x), for vector or matrix x, flags any value (row for matrices) previously seen in x. To flag all duplicated values (rows for matrices) you can use the following allDups() function.
allDups <- function(x) duplicated(x) | duplicated(x, fromLast=TRUE) > In your example, rows 2,3,4,5,8 Don't you want row 1 also, since rows 1 and 8 contain c(1,11)? Or I am again misinterpreting what you want? Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jul 21, 2014 at 12:51 PM, carol white <wht_...@yahoo.com> wrote: > I need that duplicated indicate all row indices (occurences) that are > duplicated. In your example, rows 2,3,4,5,8 > > Thanks. > > Carol > > > On Monday, July 21, 2014 9:17 PM, William Dunlap <wdun...@tibco.com> wrote: > > > 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_...@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@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@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.