R/seqfpos.R

## ===============================================================
## Search for the first occurence of a given element in a sequence
## ===============================================================

statefpos <- function (seqdata, state) {
	pos <- which(seqdata==state)
	if (length(pos)==0) fpos <- NA
	else fpos <- min(pos)
	return(fpos)
	}


seqfpos <- function (seqdata, state) {

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

	fpos <- apply(seqdata,1,statefpos,state)

	return(fpos)
	}

Try the TraMineR package in your browser

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

TraMineR documentation built on Sept. 19, 2023, 1:07 a.m.