RemoveByName | R Documentation |
Remove elements from a vector while preserving attributes
RemoveByName(x, rnames, sep = "[;,]")
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 |
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
.
x
with entries specified in rnames
removed
they will be combined using union
.
An error is thrown if removal would result in an empty vector.
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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.