R: show ALL rows with duplicated elements in a column
<p>Does a function like this exist in any package?</p>

<pre><code>isdup &lt;- function (x) duplicated (x) | duplicated (x, fromLast = TRUE)
</code></pre>

<p>My intention is to use it with <code>dplyr</code> to display <strong>all</strong> rows with duplicated values in a given column. I need the first occurrence of the duplicated element to be shown as well.</p>

<p>In this data.frame for instance</p>

<pre><code>dat &lt;- as.data.frame (list (l = c ("A", "A", "B", "C"), n = 1:4))
dat

&gt; dat
  l n
1 A 1
2 A 2
3 B 3
4 C 4
</code></pre>

<p>I would like to display the rows where column <code>l</code> is duplicated ie. those with an <strong>A</strong> value doing:</p>

<pre><code>library (dplyr)
dat %&gt;% filter (isdup (l))
</code></pre>

<p>returns</p>

<pre><code>  l n
1 A 1
2 A 2
</code></pre>