Invert the names and elements of a list

invertList(inputList, simplify = FALSE)

Arguments

inputList

a list, other classed (e.g. named vectors) will be converted to lists

simplify

Logical, if yes and if no duplicated names, return a vector

Examples

myList <- list("A"=c("a", "alpha"), "B"=c("b", "Beta"), "C"="c")
invertList(myList)
#> $Beta
#> [1] "B"
#> 
#> $a
#> [1] "A"
#> 
#> $alpha
#> [1] "A"
#> 
#> $b
#> [1] "B"
#> 
#> $c
#> [1] "C"
#> 
invertList(myList, simplify=TRUE)
#>  Beta     a alpha     b     c 
#>   "B"   "A"   "A"   "B"   "C"