swap_help: Swap by Row Index, Column Index, Element Index, and Atomic...

View source: R/swap.R

swap_helpR Documentation

Swap by Row Index, Column Index, Element Index, and Atomic Value.

Description

Swap by Row Index, Column Index, Element Index, and Atomic Value.

Usage

swap_help()

swap(x, s1, s2, type = "i")

swap_vals(x, v1, v2)

swap_elts(x, i1, i2)

swap_rows(x, i1, i2)

swap_cols(x, i1, i2)

Arguments

x

A non-empty data.frame, matrix, vlist (?VLS), or an atomic object of any dimension.

from, to

Uniquely valued non-zero whole number vectors indexing source (from) and destination (to) positions, rows, or columns. from < 0 and to < 0 index from the last value rather than the first.

old

A uniquely valued atomic vec of values to be replaced.

new

An atomic vec of replacement values. length(new) must be in c(1, length(old)).

dim

Dimension on which swapping occurs. 0 indicates swapping by element index of a non-empty vector, vlist, or other atomic object. 1 and 2 indicate, respectively, swapping rows and columns of a data.frame or matrix.

all

TRUE or FALSE indicating whether all values of x must be contained in old (ignored when old and new are NULL).

Value

An object of the same class and dimensions as x.

Functions

  • swap(): Swap elements of x either by index (when type == "i") or by value (when type == "v").

  • swap_vals(): Swap elements of x either by value, meaning that elements of x matching v1[i] are replaced by v2[i] and vice versa.

  • swap_elts(): Swap elements of x by index, meaning that element i1[i] of x is replaced by element i2[i] of and vice versa.

  • swap_rows(): Swap rows of x by index, meaning that row i1[i] of x is replaced by row i2[i] of x and vice versa.

  • swap_cols(): Swap columns of x by index, meaning that column i1[i] of x is replaced by column i2[i] of x and vice versa.

See Also

Other forks: case(), fork_help()

Examples

AF <- LETTERS[1:6]
M6 <- matrix(1:36, nrow = 6)

i1 <- 1:3
i2 <- 6:4

v1 <- c("A", "B", "C")
v2 <- c("a", "b", "c")

AF
swap_vals(AF, v1, v2)
swap_elts(AF, i1, i2)
swap(AF, v1, v2, type = "v")
swap(AF, i1, i2, type = "i")

M6
swap_rows(M6, i1, i2)
swap_cols(M6, i1, i2)

j-martineau/uj documentation built on Sept. 14, 2024, 4:40 a.m.