order_by_list: ordering of vector by list

View source: R/order-as.R

order_by_listR Documentation

ordering of vector by list

Description

order a given vector, which may contain duplicates, according to the wanted order given by some list

Usage

order_by_list(
  given,
  wanted,
  incl.unordered = TRUE,
  unordered.label = "Unlabelled"
)

order_as_list(
  given,
  wanted,
  incl.unordered = TRUE,
  unordered.label = "Unlabelled"
)

Arguments

given

the vector that needs ordering

wanted

the wanted order (list)

incl.unordered

should given elements not in wanted be kept?

unordered.label

label for the not-in-wanted elements

Value

list consisting of an index vector and a dataframe that connects the sorted elements with the corresponding list names. Also, the elements of rle applied to list.names entry of the dataframe

Examples

g <- c("b", "d", "b", "f", "c", "c", "a")
w <- list(
    "FOO" = c("a", "b"),
    "BAR" = c("c"),
    "BAZ" = c("e"),
    "QUUZ" = c("d")
)
order_by_list(g, w)
order_by_list(g, w, incl.unordered = FALSE)

renlund/descripteur documentation built on Sept. 24, 2023, 7:07 p.m.