R/seqlength.R

Defines functions seqlength

Documented in seqlength

## ==================================
## Returns a vector with the lengths
## of the sequences in seqdata
## ==================================

seqlength <- function(seqdata, with.missing=TRUE) {

	if (!inherits(seqdata,"stslist"))
		stop("data is not a sequence object, use 'seqdef' function to create one")

	sl <- ncol(seqdata)-rowSums( seqdata==attr(seqdata,"void"), na.rm=TRUE )

  if (!with.missing)
	   sl <- sl-rowSums( seqdata==attr(seqdata,"nr"), na.rm=TRUE )

	sl <- as.matrix(sl)
	colnames(sl) <- "Length"
	rownames(sl) <- rownames(seqdata)

	return(sl)
}

Try the TraMineR package in your browser

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

TraMineR documentation built on Jan. 9, 2024, 3:02 p.m.