Counts items, or finds subsequences of (integer) sequences.
count(x, sorted =TRUE) occurs(subseq, series)
Arguments
x: array of items, i.e. numbers or characters.
sorted: logical; default is to sort items beforehand.
subseq: vector of integers.
series: vector of integers.
Details
count counts the items, similar to table, but as fast and a more tractable output. If sorted then the total number per item will be counted, else per repetition.
If m and n are the lengths of s and S resp., then occurs(s, S) determines all positions i such that s == S[i, ..., i+m-1].
The code is vectorized and relatively fast. It is intended to complement this with an implementation of Rabin-Karp, and possibly Knuth-Morris-Pratt and Boyer-Moore algorithms.
Returns
count returns a list with components v the items and e the number of times it apears in the array. occurs returns a vector of indices, the positions where the subsequence appears in the series.