Learn R Programming

rank (version 0.2.0)

reorder_by_priority: Bring specified values in a vector to the front

Description

Reorders a vector so that any elements matching the values in values appear first, in the order they appear in values. All remaining elements are returned afterward, preserving their original order.

Usage

reorder_by_priority(x, priority_values)

Value

A reordered vector with priority values first, followed by all remaining elements in their original order.

Arguments

x

A character or numeric vector to reorder.

priority_values

A vector of “priority” values. Elements of x that match entries in priority_values are moved to the front in the order they appear in priority_values. Values not found in x are ignored.

Examples

Run this code
reorder_by_priority(c("A", "B", "C", "D", "E"), c("C", "A"))
reorder_by_priority(1:6, c(4, 2, 7))

Run the code above in your browser using DataLab