reindex: Reindex a data.frame

View source: R/expand.R

reindexR Documentation

Reindex a data.frame

Description

Reindexes a data.frame with a reference

Usage

reindex(
  x,
  index = NULL,
  new_index,
  expand = c("intersect", "both"),
  sort = FALSE
)

Arguments

x

A data.frame

index

The column name or number of an index to use; if NULL will assume the first column; a value of row.names will use row.names(x)

new_index

A column vector of the new index value

expand

Character switch to expand or keep only the values that intersect (none), all values in x or index, or retain all values found.

sort

Logical, if TRUE will sort the rows in output

Value

A data.frame with rows of index

Examples

iris1 <- head(iris, 5)
iris1$index <- 1:5
reindex(iris1, "index", seq(2, 8, 2))
reindex(iris1, "index", seq(2, 8, 2), expand = "both")

# Using letters will show changes in rownames
iris1$index <- letters[1:5]
reindex(iris1, "index", letters[seq(2, 8, 2)])
reindex(iris1, "index", seq(2, 8, 2))
reindex(iris1, "index", seq(2, 8, 2), expand = "both")

jmbarbone/jordan documentation built on April 1, 2024, 7:46 p.m.