title: Creating a transition matrix for each unique element in a variable
body: <p>I am having an issue with creating a transition matrix, below the the dataset that i'm working on,</p>
  
  <pre><code>Name     Rating   ID   DATE(YYYYmmdd)   
  @0CC        1   71476   20000704    
  @0CC        1   71476   20001204    
  @0RM        1   73565   20000919    
  @0RM        2   49960   20000131    
  @0RM        1   44457   20001214    
  @0RM        1   59451   20001023    
  @0TL        2   73862   20001212    
  @0TL        3   19824   20000929    
  @0TL        1   70970   20001211    
  @0TL        3   48061   20000627          
  @0TL        1   48061   20001227    
  @1AJ        1   58875   20001214    
  @1AJ        3   56014   20001214    
  @1AJ        3   47340   20001214    
  @1AJ        3   19813   20001214    
  @1AL        1   44416   20000517    
  @1AL        4   59184   20000801    
  @1AL        3   59184   20000413    
  @1AL        4   72832   20001127    
  @1AL        1   52718   20000621    
  @1AL        2   59184   20000707    
  @1AL        3   73568   20001130    
  @1AL        3   72832   20001211    
  @1AL        3   44416   20000303    
  </code></pre>
  
  <p>What i want to do is for every unique name, i would like to compare the ID, and if the ID matches, I would then look at the dates, comparing the later date with the previous date, if ratings are similar, i would ignore but if ratings is different i would like to count the number of moves.</p>
  
  <p>E.g in the first two rows, looking at Name @OCC, the ID variable matches and looking at the rating, they are similar then i do not add that to count. However,looking at @1AL, the ID variable matches thrice, looking at the dates that occur, there are three dates 20000413,20000707 and 20000801 with ratings 3,2 and 4 respectively. As ratings changed from 3 to 2 to 4 again, i would like to recorded it in a transition matrix of the following format.</p>
  
  <pre><code> From   1 2 3 4 5 (to)
    1
    2           1 
    3       1
    4
    5
  </code></pre>
  
  <p>Being quite new to this data management thing, this is what i have,</p>
  
  <pre><code>for(i in unique(dataset$Name)
  if dataset[,3]=dataset[,3]
  </code></pre>
  
  <p>which i don't think that the second line is even right. I am really really stuck and would appreciate any advice that i can get. </p>