tf_order: Rank, order and sort 'tf' vectors

tf_orderR Documentation

Rank, order and sort tf vectors

Description

These methods use tf_depth() to rank, order, and sort functional data. By default they use the modified hypograph index ("MHI") which provides an up-down ordering (lowest to highest). You can also use any of the other depth methods available via tf_depth(), or supply a custom depth function.

Usage

rank(
  x,
  na.last = TRUE,
  ties.method = c("average", "first", "last", "random", "max", "min"),
  ...
)

## Default S3 method:
rank(
  x,
  na.last = TRUE,
  ties.method = c("average", "first", "last", "random", "max", "min"),
  ...
)

## S3 method for class 'tf'
rank(
  x,
  na.last = TRUE,
  ties.method = c("average", "first", "last", "random", "max", "min"),
  depth = "MHI",
  ...
)

## S3 method for class 'tf'
xtfrm(x)

## S3 method for class 'tf'
sort(x, decreasing = FALSE, na.last = NA, depth = "MHI", ...)

Arguments

x

a tf vector.

na.last

for handling of NAs; see base::rank() and base::sort().

ties.method

a character string for handling ties; see base::rank().

...

passed to tf_depth() (e.g. arg).

depth

the depth function to use for ranking. One of the depths available via tf_depth() (default: "MHI") or a function that takes a tf vector and returns a numeric vector of depth values.

decreasing

logical. Should the sort be decreasing?

Details

rank assigns ranks based on depth values: lower depth values get lower ranks. For "MHI" this gives an ordering from lowest to highest function. For centrality-based depths ("MBD", "FM", "FSD", "RPD"), the most extreme function gets rank 1 and the most central gets the highest rank.

order returns the permutation which rearranges x into ascending order according to depth.

sort.tf returns the sorted tf vector.

xtfrm.tf returns a numeric vector of MHI depth values, enabling base::order and base::rank to work on tf vectors.

Value

rank: a numeric vector of ranks.
order: an integer vector of indices.
sort.tf: a sorted tf vector.
xtfrm.tf: a numeric vector of depth values.

See Also

tf_depth(), min.tf(), max.tf()

Other tidyfun ordering and ranking functions: tf_depth(), tf_minmax

Examples

x <- tf_rgp(5) + 1:5
rank(x)
order(x)
sort(x)
# use a centrality-based depth instead:
rank(x, depth = "MBD")

tf documentation built on April 7, 2026, 5:07 p.m.