vector_occurrence: Find the positions of first or last occurrence of unique...

View source: R/vector_occurrence.R

vector_occurrenceR Documentation

Find the positions of first or last occurrence of unique vector elements

Description

This function finds the positions of first or last occurrence of unique vector elements.

Usage

vector_occurrence(x, type = "first")

Arguments

x

[atomic()]
A vector.

type

[character(1)]
Either "first" for the first or "last" for the last occurrence.

Value

An integer vector, the positions of the unique vector elements. The ordering corresponds to unique(x), i.e., the i-th element in the output is the (first or last) occurrence of the i-th element from unique(x).

See Also

Other vector helpers: check_numeric_vector(), check_probability_vector(), chunk_vector(), insert_vector_entry(), match_numerics(), permutations(), split_vector_at(), subsets()

Examples

x <- c(1, 1, 1, 2, 2, 2, 3, 3, 3)
unique(x)
vector_occurrence(x, "first")
vector_occurrence(x, "last")

oeli documentation built on Oct. 16, 2024, 5:08 p.m.