arrange_by: Sort vector by another vector

arrange_byR Documentation

Sort vector by another vector

Description

Arranges a vector x by the order of another vector by.

Usage

arrange_by(x, by)

Arguments

x

Vector to be ordered.

by

Reference vector which x will be ordered by.

Details

Note that this function significantly differs from base::sort_by().

Value

A permutation of x.

Examples

library(magrittr)

# generate 100 random letters
random_letters <-
  letters |>
  magrittr::extract(sample.int(n = 26L,
                               size = 100L,
                               replace = TRUE)) %T>%
  print()

# sort the random letters alphabetically
random_letters |> pal::arrange_by(by = letters)

salim-b/pal documentation built on Feb. 28, 2025, 6:51 p.m.