R/SQSIndex.R

Defines functions SQSIndex

Documented in SQSIndex

#' Matrix Indicating which Sequences have which SQS's
#'
#' @param allsqs Matrix of all the possible sequence silhouettes.
#' @param sqslist List of SQS's found in each sequence.
#'
#' @return Index Matrix indicating which sequences have which SQS's.
#' @export
#'
#' @examples
#' df<-data.frame(Time=c("2020-01-01 00:10:09", "2020-01-01 01:12:34" , "2020-01-02 06:38:09",
#' "2020-01-02 07:21:51"),Cat=c('A','B','A','C'))
#' #For daily data:
#' seqlist<-SeqList(df,'%Y-%m-%d')
#' sqslist<-SQSList(seqlist,2)
#' allsqs<-AllSQS(c('A','B','C'),2)
#' SQSIndex(allsqs,sqslist)
SQSIndex <- function(allsqs, sqslist) {
  SIndex <- matrix(0, dim(allsqs)[1], length(sqslist))
  for (j in 1:length(sqslist)) {
    for (i in 1:dim(allsqs)[1]) {
      if (sum(apply(sqslist[[j]], 1, function(x) identical(x, allsqs[i, ]))) != 0) {
        SIndex[i, j] <- 1
      }
    }
  }
  return(as.data.frame(SIndex))
}
jgillam13/IRASD documentation built on Feb. 10, 2021, 9:38 a.m.