When looking for duplicate rows in an array,
base::duplicated returns an array of dimension n \times 1 for an equally sized input array. Is this a bug or intended behavior?
Here is a minimal reproducible example:
duplicated( cbind( c(1, 2, 3, 1) ) )
Background: I am working on a function that detects duplicate records in a dataset. For reasons beyond the scope of this post, callers provide the data as atomic vectors via the dot-operator. On runtime, my function internally calls
cbind() to construct a matrix from the input after it has been validated.
For all cases in which
cbind(...) evaluates to a matrix with at least two columns, duplicated returns a logical vector. From my understanding of
?duplicated this seems to be the intended behavior. However, when fed a single vector -- as in the example above -- duplicated will return a n \times 1 matrix, violating my design contracts.
There are of course simple fixes, e.g.,
as.vector, however, I want to understand the problem before I fix it.
Edit: I did not change the default value for
duplicated's MARGIN argument, i.e., my function compares rows.