Count occurences of all possible substrings in one more strings.

count.substring.occurrences(strings, sortbylength = FALSE)

Arguments

strings

a list or vector of character sequences

sortbylength

logical indicating whether the substring columns should be ordered according to the (decreasing) length of the substrings. Default is to leave them in the original order in which they occur in the given strings.

Value

A matrix with the original strings along rows and all substrings of those strings along columns. The cell values indicate whether (and how many times) the substring is contained in each of the strings.

Examples

count.substring.occurrences(c("asd", "asdd", "foo"))
#> a as asd s sd d asdd sdd dd f fo foo o oo #> asd 1 1 1 1 1 1 0 0 0 0 0 0 0 0 #> asdd 1 1 1 1 1 2 1 1 1 0 0 0 0 0 #> foo 0 0 0 0 0 0 0 0 0 1 1 1 2 1