| cover | R Documentation |
Calculates the cardinality of substring family (the covering) and returns valid elements.
cover(x, valid. = FALSE, wplot = FALSE)
x |
integer, length = 1 or character vector, length > 1, or character string |
valid. |
logical, default, FALSE. When TRUE, valid substrings are returned. Requires character or string |
wplot |
logical, FALSE. When TRUE, displays a plot of combinations versus number of characters in string |
This function finds the total, the minimum and the maximum number of combinations of individual string covering or returns a subset of valid substrings (i.e. elements of the string) by retaining even transpositions inside the combinations matrix.
NOTE 1: Herein, the covering represents the substring family that preserves the order of characters inside
the string. Hence, the use of combinations instead of partial permutations, n!/(n-r)!, as the order
inside each selection group r is irrelevant.
NOTE 2: Very long strings may result in memory allocation error when valid. = TRUE. Use fcommon instead.
NOTE 3: When x is an integer associated with an existing string, x must equal either nchar(string)
or length(character).
When valid. = FALSE a prettified named vector showing the total, minimum and maximum number of
combinations for respective string covering. When valid. = TRUE, a character vector of valid substrings
longer than 2 characters each. In both cases, a plot is returned when wplot = TRUE.
fcommon
if (interactive()) {
# 1. x is a character
# 1.1 A string
x = 'tyrvvsvltvlhqdwlngkeykck'
a = cover(x)
print(a)
# 1.2 A vector
x = strsplit(x, '')[[1]]
b = cover(x)
print(b)
# 2. An integer
n = length(x)
c = cover(n)
print(c)
# 3. Valid substrings with plot
d = cover(x, valid. = TRUE, wplot = TRUE)
print(head(d, 30))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.