SUMMARY: counting duplicates

Bruce McCullough (
Tue, 27 Jan 1998 09:00:39 -0500

Many thanks to those who offered advice.
Many user-defined functions were offered. The
shortest (and fastest of the few I tried) was offered
by several persons, including Douglas Bates and Brian Ripley.
Below is Ripley's code:

1) table() to find the numbers of occurrences.
(2) match to find the right table name
(3) indexing to make the answer


countdup <- function(x)
tab <- table(x)
y <- match(x, names(tab))