R/seqcomplete.R

Defines functions seqcomplete

Documented in seqcomplete

#' Extract all the trajectories without missing value.
#'
#' @param data either a data frame containing sequences of a multinomial
#' variable with missing data (coded as \code{NA}) or a state sequence
#' object built with the TraMineR package
#' @param var the list of columns containing the trajectories.
#' Default is NULL, i.e. all the columns.
#' @return Returns either a data frame or a state sequence object, depending
#' the type of data that was provided to the function
#'
#' @examples
#'
#' # Game addiction dataset
#' data(gameadd)
#' # Extract the trajectories without any missing data
#' gameadd.complete <- seqcomplete(gameadd, var = 1:4)
#'
#' @author Kevin Emery
#'
#' @export
seqcomplete <- function(data, var = NULL) {
  data <- dataxtract(data, var)
  if (inherits(data, "stslist")) {
    rowsNA <- rowSums(data == attr(data, "nr"))
  } else {
    rowsNA <- rowSums(is.na(data))
  }
  return(data[rowsNA == 0, ])
}

Try the seqimpute package in your browser

Any scripts or data that you put into this service are public.

seqimpute documentation built on April 12, 2025, 1:54 a.m.