powered by
Simple conversion functions for discrete data (e.g., time series), between 0:k integers and single letter characters.
0:k
alpha2int(x, alpha) int2alpha(i, alpha)
alpha2int(x,*) returns an integer vector of the same length as x, consisting of values from 0:k where
alpha2int(x,*)
integer
x
k + 1 is the length of the alphabet, nchar(alpha).
k + 1
nchar(alpha)
int2alpha(i,*) returns a vector of single letter
int2alpha(i,*)
character of the same length as i.
character
i
character vector of single letters.
the alphabet, as one character string.
integer vector of numbers in 0:k.
vlmc, and int2char() and its inverse, char2int(), both working with multi-character strings instead of vectors of single characters; further, alphabet.
vlmc
int2char()
char2int()
alphabet
alphabet <- "abcdefghijk" (ch <- sample(letters[1:10], 30, replace = TRUE)) (ic <- alpha2int(ch, alphabet)) stopifnot(int2alpha(ic, alphabet) == ch)
Run the code above in your browser using DataLab