Provide the mapping between keys and values in a structure of choice
toLookupClass(keys, values, class = c("data.frame.1", "data.frame.2", "list", "vector")[1])
keys | vector of keys |
---|---|
values | vector of values |
class | character string determining the class of the structure
returned: "data.frame.1": data frame with the |
object according to the chosen class
. See description of the
class
argument.
keys <- c("A", "B", "C") values <- c("Apple", "Banana", "Cherry") fruits.df1 <- toLookupClass(keys, values) fruits.df2 <- toLookupClass(keys, values, class = "data.frame.2") fruits.list <- toLookupClass(keys, values, class = "list") fruits.vector <- toLookupClass(keys, values, class = "vector") # Note how you may use the results differently fruits.df1$A#> [1] "Apple"fruits.list$A#> [1] "Apple"fruits.vector["A"]#> A #> "Apple"fruits.df1[c("A", "C")]#> A C #> 1 Apple Cherryfruits.list[c("A", "C")]#> $A #> [1] "Apple" #> #> $C #> [1] "Cherry" #>fruits.vector[c("A", "C")]#> A C #> "Apple" "Cherry"