Create Dictionary from Unique Strings
to_dictionary(x, prefix = "a", leading_zeros = FALSE)
x | vector of strings |
---|---|
prefix | prefix to be given to the keys in the dictionary. Default: "a" |
leading_zeros | whether to make all keys in the dictionary have same
length by adding leading zeros to the keys. Default: |
# Define input strings x <- c("elephant", "mouse", "cat", "cat", "cat", "mouse", "cat", "cat") # Create a dictionary for the unique values in x kwb.pathdict:::to_dictionary(x)#> $a1 #> [1] "cat" #> #> $a2 #> [1] "mouse" #> #> $a3 #> [1] "elephant" #># Note that "cat" is the first entry because it has the highest "importance" kwb.pathdict:::sorted_importance(x)#> x #> cat mouse elephant #> 15 10 8