TransMx: Transition matrices in one group of strings

Description Usage Arguments Value Note See Also Examples

View source: R/TransMx.R

Description

TransMx discovers transition matrix of a string vector and the related information.

A transition is defined as a substring (in the forward order) with length of 2 characters.

Usage

1
TransMx(strings.vec, indiv = FALSE)

Arguments

strings.vec

String Vector.

If a string has fewer than 2 characters, that string will be ignored.

indiv

Whether exports transition matrix for each string into the current directory. Default value is FALSE.

Value

The function returns a list, which contains the transition matrix, the normalized matrix, and the sorted numbers of transitions.

If indiv = TRUE, a set of mx.txt files are exported into the current directory that contain transition matrix for each string. The names of these files are the name of strings.vec appended with the orders of the strings in the string vector. If a string has fewer than 2 characters, the corresponding mx.txt file will be skipped.

Note

Strings with less than 2 characters are not included due to the definition of transition.

See Also

TransInfo

Examples

1
2
3
4
5
6
7
# simple strings
strs.vec <- c("ABCDdefABCDa", "def123DC", "123aABCD", "ACD13", "AC1ABC", "3123fe")
TransMx(strs.vec)

# simple strings, export an individual transition matrix for each string
strs.vec <- c("ABCDdefABCDa", "def123DC", "123aABCD", "ACD13", "AC1ABC", "3123fe")
TransMx(strs.vec, indiv = TRUE)

Example output

$Transition_Matrix
   From/To 1 2 3 A B C D a d e f
1        1 0 3 1 1 0 0 0 0 0 0 0
2        2 0 0 3 0 0 0 0 0 0 0 0
3        3 1 0 0 0 0 0 1 1 0 0 1
4        A 0 0 0 0 4 2 0 0 0 0 0
5        B 0 0 0 0 0 4 0 0 0 0 0
6        C 1 0 0 0 0 0 4 0 0 0 0
7        D 1 0 0 0 0 1 0 1 1 0 0
8        a 0 0 0 1 0 0 0 0 0 0 0
9        d 0 0 0 0 0 0 0 0 0 2 0
10       e 0 0 0 0 0 0 0 0 0 0 2
11       f 1 0 0 1 0 0 0 0 0 1 0

$Transition_Normalized_Matrix
      From/To 1      2      3      A      B      C      D      a      d     
 [1,] 1       0      0.0769 0.0256 0.0256 0      0      0      0      0     
 [2,] 2       0      0      0.0769 0      0      0      0      0      0     
 [3,] 3       0.0256 0      0      0      0      0      0.0256 0.0256 0     
 [4,] A       0      0      0      0      0.1026 0.0513 0      0      0     
 [5,] B       0      0      0      0      0      0.1026 0      0      0     
 [6,] C       0.0256 0      0      0      0      0      0.1026 0      0     
 [7,] D       0.0256 0      0      0      0      0.0256 0      0.0256 0.0256
 [8,] a       0      0      0      0.0256 0      0      0      0      0     
 [9,] d       0      0      0      0      0      0      0      0      0     
[10,] e       0      0      0      0      0      0      0      0      0     
[11,] f       0.0256 0      0      0.0256 0      0      0      0      0     
      e      f     
 [1,] 0      0     
 [2,] 0      0     
 [3,] 0      0.0256
 [4,] 0      0     
 [5,] 0      0     
 [6,] 0      0     
 [7,] 0      0     
 [8,] 0      0     
 [9,] 0.0513 0     
[10,] 0      0.0513
[11,] 0.0256 0     

$Transition_Organized
   transition number_of_transition
1          AB                    4
2          BC                    4
3          CD                    4
4          12                    3
5          23                    3
6          AC                    2
7          de                    2
8          ef                    2
9          31                    1
10         C1                    1
11         D1                    1
12         f1                    1
13         13                    1
14         1A                    1
15         aA                    1
16         fA                    1
17         DC                    1
18         3D                    1
19         3a                    1
20         Da                    1
21         Dd                    1
22         fe                    1
23         3f                    1

$Transition_Matrix
   From/To 1 2 3 A B C D a d e f
1        1 0 3 1 1 0 0 0 0 0 0 0
2        2 0 0 3 0 0 0 0 0 0 0 0
3        3 1 0 0 0 0 0 1 1 0 0 1
4        A 0 0 0 0 4 2 0 0 0 0 0
5        B 0 0 0 0 0 4 0 0 0 0 0
6        C 1 0 0 0 0 0 4 0 0 0 0
7        D 1 0 0 0 0 1 0 1 1 0 0
8        a 0 0 0 1 0 0 0 0 0 0 0
9        d 0 0 0 0 0 0 0 0 0 2 0
10       e 0 0 0 0 0 0 0 0 0 0 2
11       f 1 0 0 1 0 0 0 0 0 1 0

$Transition_Normalized_Matrix
      From/To 1      2      3      A      B      C      D      a      d     
 [1,] 1       0      0.0769 0.0256 0.0256 0      0      0      0      0     
 [2,] 2       0      0      0.0769 0      0      0      0      0      0     
 [3,] 3       0.0256 0      0      0      0      0      0.0256 0.0256 0     
 [4,] A       0      0      0      0      0.1026 0.0513 0      0      0     
 [5,] B       0      0      0      0      0      0.1026 0      0      0     
 [6,] C       0.0256 0      0      0      0      0      0.1026 0      0     
 [7,] D       0.0256 0      0      0      0      0.0256 0      0.0256 0.0256
 [8,] a       0      0      0      0.0256 0      0      0      0      0     
 [9,] d       0      0      0      0      0      0      0      0      0     
[10,] e       0      0      0      0      0      0      0      0      0     
[11,] f       0.0256 0      0      0.0256 0      0      0      0      0     
      e      f     
 [1,] 0      0     
 [2,] 0      0     
 [3,] 0      0.0256
 [4,] 0      0     
 [5,] 0      0     
 [6,] 0      0     
 [7,] 0      0     
 [8,] 0      0     
 [9,] 0.0513 0     
[10,] 0      0.0513
[11,] 0.0256 0     

$Transition_Organized
   transition number_of_transition
1          AB                    4
2          BC                    4
3          CD                    4
4          12                    3
5          23                    3
6          AC                    2
7          de                    2
8          ef                    2
9          31                    1
10         C1                    1
11         D1                    1
12         f1                    1
13         13                    1
14         1A                    1
15         aA                    1
16         fA                    1
17         DC                    1
18         3D                    1
19         3a                    1
20         Da                    1
21         Dd                    1
22         fe                    1
23         3f                    1

GrpString documentation built on May 2, 2019, 12:38 p.m.