stacey thompson
2007-Mar-08 17:07 UTC
[R] Removing duplicated rows in a matrix, with missing data as wildcards
I'd like to remove duplicated rows within a matrix, with missing data being treated as wildcards. For example> x <- matrix((1:3), 5, 3) > x[4,2] = NA > x[3,3] = NA > x[,1] [,2] [,3] [1,] 1 3 2 [2,] 2 1 3 [3,] 3 2 NA [4,] 1 NA 2 [5,] 2 1 3 I would like to obtain [,1] [,2] [,3] [1,] 1 3 2 [2,] 2 1 3 [3,] 3 2 NA>From the R-help archives, I learned about unique(x) and duplicated(x).However, unique(x) returns> unique(x)[,1] [,2] [,3] [1,] 1 3 2 [2,] 2 1 3 [3,] 3 2 NA [4,] 1 NA 2 and duplicated(x) gives> duplicated(x)[1] FALSE FALSE FALSE FALSE TRUE I have tried various na.action 's but with unique(x) I get errors at best. e.g.> unique(x, na.omit(x))Error: argument 'incomparables != FALSE' is not used (yet) How I might tackle this? Thanks, -stacey -- -stacey lee thompson- Stagiaire post-doctorale Institut de recherche en biologie v?g?tale Universit? de Montr?al 4101 Sherbrooke Est Montr?al, Qu?bec H1X 2B2 Canada stacey.thompson at umontreal.ca