vector_occurrence {oeli}R 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

A vector.

type

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 ii-th element in the output is the (first or last) occurrence of the ii-th element from unique(x).

Examples

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

[Package oeli version 0.5.2 Index]