RemoveByName: Remove indices from a vector by name

View source: R/removebyname.R

RemoveByNameR Documentation

Remove indices from a vector by name

Description

Remove elements from a vector while preserving attributes

Usage

RemoveByName(x, rnames, sep = "[;,]")

Arguments

x

Named vector, data.frame, or list to remove entries from, or a list of these; see the details.

rnames

Either 1) a character, vector giving entry names to remove; 2) a single string containing comma or semi-colon separated names to remove, 3) a list where each element is either 1) or 2).

sep

Character string specifying a possible separator in rnames. Can be a regular expression; the default checks for both "," and ";".

Details

In the case when x inherits from class "list", it is first checked whether any of rnames appears in the names of the elements of x; if they do, then elements will be removed from each element of x. If the the check finds no matches in any element, then an attempt is made to remove entire elements of x whose names appear in rnames.

Value

x with entries specified in rnames removed they will be combined using union.

Note

An error is thrown if removal would result in an empty vector.

Examples

x <- c(a = 1, b = 2, c = 3, d = 4, e = 5)
RemoveByName(x, "a")
RemoveByName(x, "a; b")
RemoveByName(x, list(c("a", "b"), " c,  d"))

NumbersInternational/flipU documentation built on March 2, 2024, 10:55 a.m.