0
$\begingroup$

How can I select the duplicate values in a list?

Example:

{1, 2, 1, 1, 1, 1}
$\endgroup$
  • $\begingroup$ I need to return the duplicate values. $\endgroup$ – BetterEnglish Jun 9 '14 at 15:07
  • $\begingroup$ So in your example what do you need to return? $\endgroup$ – Öskå Jun 9 '14 at 15:08
  • $\begingroup$ I need to return {1} $\endgroup$ – BetterEnglish Jun 9 '14 at 15:15
  • $\begingroup$ Have you even looked at the link above? It returns {1}. Please make an effort. $\endgroup$ – Öskå Jun 9 '14 at 15:17
  • $\begingroup$ @Öskå, I am so sorry! thanks $\endgroup$ – BetterEnglish Jun 9 '14 at 15:20
0
$\begingroup$

If you want all duplicates then:

list = {1, 2, 1, 1, 1, 1}

Select[Split@Sort@list, Length@# > 1 &]

if you want one from each duplicate then

Select[Split@Sort@list, Length@# > 1 &][[;;,1]]
| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.