I have a vector with random numbers from 1-7 and I want to be able to determine the next number in the vector that follows the first value so that I can look for patterns and get a 7x7 matrix of values that shows how often a specific number follows another.
First number in rows and count of next number in columns.
I am trying to do this with a double loop currently, but am getting confused in the process.
For example-
Example vector-
floor(runif(10,1,8))
[1] 3 5 6 6 6 1 7 7 5 3
Answer-
1 2 3 4 5 6 7
1 0 0 0 0 0 0 1
2 NA NA NA NA NA NA NA
3 0 0 0 0 1 0 0
4 NA NA NA NA NA NA NA
5 0 0 1 0 0 1 0
6 1 0 0 0 0 3 0
7 0 0 0 0 1 0 1