seqpm: Find substring patterns in sequences

Description Usage Arguments Details Value Author(s) Examples

View source: R/seqpm.R

Description

Search for a pattern (substring) into sequences.

Usage

1
 seqpm(seqdata, pattern, sep="")

Arguments

seqdata

a sequence object as defined by the seqdef function.

pattern

a character string representing the pattern (substring) to search for.

sep

state separator used in the pattern definition.

Details

This function searches a pattern (a character string) into a set of sequences and returns the results as a list with two elements: 'Nbmatch' the number of occurrences of the pattern and 'MatchesIndex' the vector of indexes (row numbers) of the sequences that match the pattern (see examples below).

Value

a list with two elements (see details).

Author(s)

Alexis Gabadinho

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
data(actcal)
actcal.seq <- seqdef(actcal,13:24)

## search for pattern "DAAD"
## (no work-full time work-full time work-no work)
## results are stored in the 'daad' object
daad <- seqpm(actcal.seq,"DAAD")

## Looking at the sequences
## containing the pattern
actcal.seq[daad$MIndex,]

## search for pattern "AD"
## (full time work-no work)
seqpm(actcal.seq,"AD")

Example output

TraMineR stable version 2.0-6 (Built: "Mon,)
Website: http://traminer.unige.ch
Please type 'citation("TraMineR")' for citation information.

 [>] 4 distinct states appear in the data: 
     1 = A
     2 = B
     3 = C
     4 = D
 [>] state coding:
       [alphabet]  [label]  [long label] 
     1  A           A        A
     2  B           B        B
     3  C           C        C
     4  D           D        D
 [>] 2000 sequences in the data set
 [>] min/max sequence length: 12/12
 [>] pattern DAAD has been found in 4 sequences
     Sequence               
3660 D-A-A-D-D-D-D-D-D-A-A-A
6829 D-D-A-A-D-D-A-A-A-A-A-A
6040 D-D-B-B-C-D-D-A-A-D-C-C
5489 D-D-D-D-A-A-D-A-B-B-D-D
 [>] pattern AD has been found in 60 sequences
$MTab
  pattern nbocc
1      AD    60

$MIndex
 [1]    2   23   28   52   54   79   99  107  168  170  177  192  234  263  291
[16]  362  480  561  600  663  722  780  783  784  841  849  869  877  914  922
[31]  946  961  964  967  986 1005 1091 1145 1197 1243 1249 1353 1490 1579 1632
[46] 1685 1699 1729 1743 1746 1773 1797 1810 1820 1838 1845 1876 1897 1914 1937

TraMineR documentation built on June 3, 2021, 5:06 p.m.