title: Find duplicate values in R
body: <p>I have a table with 21638 unique* rows:</p>
  
  <pre><code>vocabulary &lt;- read.table("http://socserv.socsci.mcmaster.ca/jfox/Books/Applied-Regression-2E/datasets/Vocabulary.txt", header=T)
  </code></pre>
  
  <p>This table has five columns, the first of which holds the respondent ID numbers. I want to check if any respondents appear twice, or if all respondents are unique.</p>
  
  <p>To count unique IDs I can use</p>
  
  <pre><code>length(unique(vocabulary$id))
  </code></pre>
  
  <p>and to check if there are any duplicates I might do</p>
  
  <pre><code>length(unique(vocabulary$id)) == nrow(vocabulary)
  </code></pre>
  
  <p>which returns <code>TRUE</code>, if there are no duplicates (which there aren't).</p>
  
  <p><strong>My question:</strong></p>
  
  <p>Is there a direct way to return the values or line numbers of duplicates?</p>
  
  <p><strong>Some further explanation:</strong></p>
  
  <p>There is an interpretation problem with using the function <code>duplicated()</code>, because is only returns the duplicates in the strict sense, excluding the "originals". For example, <code>sum(duplicated(vocabulary$id))</code> or <code>dim(vocabulary[duplicated(vocabulary$id),])[1]</code> might return "5" as the number of duplicate rows. The problem is that if you only know the number of duplicates, you won't know how many rows they duplicate. Does "5" mean that there are five rows with one duplicate each, or that there is one row with five duplicates? And since you won't have the IDs or line numbers of the duplicates, you wouldn't have any means of finding the "originals".</p>
  
  <hr>
  
  <p>*<em>I know there are no duplicate IDs in this survey, but it is a good example, because using any of the answers given elsewhere to this question, like <code>duplicated(vocabulary$id)</code> or <code>table(vocabulary$id)</code> will output a haystack to your screen in which you'll be quite unable to find any possible rare duplicate needles.</em></p>