title: Counting unique values across variables (columns) in R
body: <p>I have a large dataset with repeated measures over 5 time periods. </p>
  
  <pre><code>   2012  2009  2006  2003  2000
      3     1     4     4     1
      5     3     2     2     3
      6     7     3     5     6 
  </code></pre>
  
  <p>I want to add a new column, which is the number of unique values among years 2000 to 2012. e.g., </p>
  
  <pre><code>   2012  2009  2006  2003  2000  nunique
      3     1     4     4     1      3
      5     3     2     2     3      3
      6     7     3     5     6      4
  </code></pre>
  
  <p>I am working in R and, if it helps, there are only 14 possible different values of the measured value at each time period.  </p>
  
  <p>I found this page: <a href="https://stackoverflow.com/questions/24015557/count-occurrences-of-value-in-a-set-of-variables-in-r-per-row">Count occurrences of value in a set of variables in R (per row)</a> and tried the various solutions offered on it. What it gives me however is a count of each value, not the number of unique values. 
  Other similar questions on here seem to ask about counting number of unique values within a variable /column, rather than across each row. 
  Any suggestions would be appreciated. </p>