#' Matrix of Possible Sequence Silhouettes
#'
#'Given a sequence, the function searches through to find all the possible sequence silhouettes.
#'
#' @param testseq Categorical sequence of interest.
#' @param k Maximum length of sequence silhouette.
#'
#' @return Matrix of possible sequence silhouettes for the test sequence.
#' @export
#'
#' @examples
#' SQS(c("A", "B", "A", "C"), 2)
SQS <- function(testseq, k) {
b <- 1
k <- min(length(testseq) - 1, k - 1)
a <- matrix(NA, (k+1) * length(testseq) - sum(0:k), 3)
for (m in 0:k) {
for (l in 1:(length(testseq) - m)) {
a[b, 1] <- as.character(testseq[l])
a[b, 2] <- as.character(testseq[l + m])
a[b, 3] <- m
b <- b + 1
}
}
if (dim(a)[1] > 1) {
a <- as.matrix(a[!duplicated(a), ])
}
return(a)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.