# distinct: Distinct elements of a list In smerc: Statistical Methods for Regional Counts

 distinct R Documentation

## Distinct elements of a list

### Description

`distinct` takes a list of integer vectors and returns the list indices that contain unique combinations of elements. This function is NOT robust against misuse, so please use properly.

### Usage

```distinct(x, N = max(unlist(x)))
```

### Arguments

 `x` A list of integers `N` The largest integer value across all elements of `x`.

### Details

Assume that `k` is the largest integer value in `x`. A vector of the largest `k` prime numbers is obtained (call this `pri`). The algorithm takes the sum of the log of `pri[x[[i]]]` for each element of `x`, and determines which sums are unique. This is why the elements of `x` must be integer vectors. The prime aspect of the algorithm is critical, as it ensures that a none of the values are multiples of the others, ensuring uniqueness.

Note: this algorithm has only been applied to data sets where each element of `x[[i]]` appears only once, though it should work for repeats also.

### Value

A vector with the distinct indices.

Joshua French

### References

Algorithm based on suggestion at https://stackoverflow.com/a/29824978.

### Examples

```x <- list(1:3, 3:1, 1:4, 4:1, c(1, 2, 4, 6), c(6, 4, 1, 2))
x[distinct(x)]
```

smerc documentation built on Oct. 13, 2022, 9:07 a.m.