Hervé Pagès
2011-Nov-17 06:40 UTC
[Rd] inaccuracy in man page for duplicated() + anyDuplicated() not working with MARGIN=0
Hi,
In man page for duplicated:
Value:
?duplicated()?: For a vector input, a logical vector of the same
length as ?x?. For a data frame, a logical vector with one
element for each row. For a matrix or array, a logical array with
the same dimensions and dimnames.
When 'x' is a matrix or array, the returned value is NOT a logical
array:
> m <- matrix(c(3,2,7,6,2,7), nrow=3)
> m
[,1] [,2]
[1,] 3 6
[2,] 2 2
[3,] 7 7
> duplicated(m)
[1] FALSE FALSE FALSE
Only if MARGIN=0 it seems:
> duplicated(m, MARGIN=0)
[,1] [,2]
[1,] FALSE FALSE
[2,] FALSE TRUE
[3,] FALSE TRUE
Also, any reason why this doesn't work?
> anyDuplicated(m, MARGIN=0)
Error in dim(newX) <- c(prod(d.call), d2) :
dims [product 1] do not match the length of object [6]
May be it could be equivalent to:
> anyDuplicated(as.vector(m))
[1] 5
Thanks,
H.
--
Herv? Pag?s
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpages at fhcrc.org
Phone: (206) 667-5791
Fax: (206) 667-1319
Martin Maechler
2011-Nov-17 11:20 UTC
[Rd] inaccuracy in man page for duplicated() + anyDuplicated() not working with MARGIN=0
> Hi, > In man page for duplicated:> Value:> ?duplicated()?: For a vector input, a logical vector of the same > length as ?x?. For a data frame, a logical vector with one > element for each row. For a matrix or array, a logical array with > the same dimensions and dimnames.> When 'x' is a matrix or array, the returned value is NOT a logical > array:> > m <- matrix(c(3,2,7,6,2,7), nrow=3) > > m > [,1] [,2] > [1,] 3 6 > [2,] 2 2 > [3,] 7 7 > > duplicated(m) > [1] FALSE FALSE FALSE> Only if MARGIN=0 it seems:> > duplicated(m, MARGIN=0) > [,1] [,2] > [1,] FALSE FALSE > [2,] FALSE TRUE > [3,] FALSE TRUEIndeed. Thank you for pointing this out. I'll definitely fix that part of the help file.> Also, any reason why this doesn't work?> > anyDuplicated(m, MARGIN=0) > Error in dim(newX) <- c(prod(d.call), d2) : > dims [product 1] do not match the length of object [6]well, because the R core colleague enhanced duplicated.array() to work with MARGIN 0 (and similar cases) did not update the parallel code in anyDuplicated.array() correspondingly.> May be it could be equivalent to:> > anyDuplicated(as.vector(m)) > [1] 5Yes, that's what will happen after I've committed my fixes. Thank you very much, Herv?! Martin [...]> -- > Herv? Pag?s[...] (*) having authored anyDuplicated()
Maybe Matching Threads
- anyDuplicated(incomp=NA) fails
- 1.6x speedup for requal() function (in R/src/main/unique.c)
- small inaccuracy in startup warning message
- head.matrix can return 1000s of columns -- limit to n or add new argument?
- MARGIN in base::unique.matrix() and base::unique.array()