set.seed(0)
# test a numeric vector
x = rnorm(7)
y = rnorm(5)
grpDuplicated( c(x,y,rev(x)) )
## [1] 7 6 5 4 3 2 1 0 0 0 0 0 1 2 3 4 5 6 7
## attr(,"ngroups")
## [1] 12 5 7
# test a numeric matrix, both rows and columns
A = matrix( rnorm(3*7), 3, 7 )
B = matrix( rnorm(3*5), 3, 5 )
# the columns of cbind(A,B,A) have the duplicates one would expect
grpDuplicated( cbind(A,B,A), MARGIN=2 )
## [1] 1 2 3 4 5 6 7 0 0 0 0 0 1 2 3 4 5 6 7
## attr(,"ngroups")
## [1] 12 5 7
# but the rows of cbind(A,B,A) are unique
grpDuplicated( cbind(A,B,A), MARGIN=1 )
## [1] 0 0 0
## attr(,"ngroups")
## [1] 3 3 0
Run the code above in your browser using DataLab