triple.counts: Count Triplets in Character Vectors

Description Usage Arguments Details Value Author(s) See Also


Count triples of adjacent symbols/elements in a character vector.


triple.counts(x, case=c("lower", "upper", "as is"), circular=TRUE)



a character vector or an object that can be coersed to a character vector.


determines how labels for the array should be generated: in 'lower' case, in ' upper' case or 'as is', in which case labels such as 'b' and 'B' will be counted as distinct elements and counted separately.


Determines if the vector should be treated as circular or not. The default is TRUE, meaning that the start and end of the sequence will be joined together for the purpose of counting.


If circular is TRUE, the vector is treated as circular so that the some of all the counts in the resulting array is equal to the length of the vector and the sums across all dimentions of the array are equivalent, that is: if we write
t <- triple.counts(x)
for some character sequence x, then
apply(t,1,sum), apply(t,2,sum) and apply(t,3,sum)
are all identical.

On the other hand, if circular is FALSE, the sum of all the entries in the counts array will be two less than the length of the vector and there will be a discrepancy between the sums over the various dimensions.


A 3-dimensional array of counts. The labels of the i-th dimension correspond to the i-th element of each triple, where i is either 1, 2 or 3.


Andrew Hart and Servet Mart<ed>nez

See Also

pair.counts, quadruple.counts, cylinder.counts, array2vector, table2vector

Search within the spgs package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.