Convert string descriptions of competitors into their number

character_to_number(char, pnames)
char2num(char, pnames)

Arguments

char

Character vector to be converted

pnames

Names vector (usually pnames(H))

Details

In earlier versions of this package, the internal mechanism of functions such as ggrl(), and all the C++ code, operated with the competitors labelled with a non-negative integer; it is then natural to refer to the competitors as p1, p2, etc.

However, sometimes the competitors have names (as in, for example, the rowing dataset). If so, it is more natural to refer to the competitors using their names rather than an arbitrary integer.

Function character_to_number() converts the names to numbers. If an element of char is not present in pnames, an error is returned (function char2num() is an easy-to-type synonym). The function is here because it is used in ggrl().

Author

Robin K. S. Hankin

See also

Examples

 x <- sample(9)
 names(x) <- sample(letters[1:9])
 H <- rank_likelihood(x)
 character_to_number(letters[1:3],pnames(H))
#> [1] 8 4 5

 char2num(c("PB","L"),pnames(icons))
#> [1] 3 2