flip: Flip vector names and values

Description Usage Arguments Value Author(s) Examples

Description

Simply flips or switches values and names of named vectors. This is e.g. useful when named character vectors are used a mapping.

Usage

1
flip(x, convert = TRUE)

Arguments

x

A named vector.

convert

logical. If TRUE, an attempt will be made to coerce the flipped values into a numeric.

Value

A named character vector.

Author(s)

Anders Ellern Bilgrau

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- structure(1:5, names = LETTERS[1:5])
x
flip(x)
flip(flip(x))


y <- structure(c("a", "b", "c", "d", "e", "f", "g"), 
   names = c("albert", "bob", "charlie", "dennis", "eddie", "frank", "hugo"))
y["hugo"]
flip(y)["a"]

AEBilgrau/Bmisc documentation built on May 5, 2019, 11:28 a.m.