Learn R Programming

rearrr (version 0.3.5)

by_distance_rearranger_: Wrapper for running closest to / furthest from rearrange methods

Description

Wrapper for running closest to / furthest from rearrange methods

Usage

by_distance_rearranger_(
  data,
  cols,
  origin = NULL,
  origin_fn = NULL,
  shuffle_ties = FALSE,
  decreasing = FALSE,
  origin_col_name = ".origin",
  distance_col_name = ".distance",
  overwrite = FALSE
)

Value

The sorted data.frame (tibble) / vector.

Arguments

data

data.frame or vector.

cols

Column(s) to create sorting factor by. When `NULL` and `data` is a data.frame, the row numbers are used.

origin

Coordinates of the origin to calculate distances to. A scalar to use in all dimensions or a vector with one scalar per dimension.

N.B. Ignored when `origin_fn` is not `NULL`.

origin_fn

Function for finding the origin coordinates.

Input: Each column will be passed as a vector in the order of `cols`.

Output: A vector with one scalar per dimension.

Can be created with create_origin_fn() if you want to apply the same function to each dimension.

E.g. `create_origin_fn(median)` would find the median of each column.

Built-in functions are centroid(), most_centered(), and midrange()

shuffle_ties

Whether to shuffle elements with the same distance to the origin. (Logical)

decreasing

Whether to order by decreasing distances to the origin. (Logical)

origin_col_name

Name of new column with the origin coordinates. If `NULL`, no column is added.

distance_col_name

Name of new column with the distances to the origin. If `NULL`, no column is added.

overwrite

Whether to allow overwriting of existing columns. (Logical)