On Aug 7, 2013, at 11:23 PM, Kevin Parent wrote:

> Well that almost works, and I didn't know about duplicated() so thanks for 
> that. However, it only gives me the duplicated values. I need the original 
> ones too. So the result I want is: [g,g,m,m,s,s,t,t,u,u,u,v,v,x,x,y,y,y]. 
> What duplicated() gives me is [g,m,s,t,u,u,v,x,y,y]

x[ duplicated(x) | duplicated(x, fromLast=TRUE) ]

-- 
David.
>  
> Playing around with it, I got this but can't helping thinking there must be a 
> less awkward way:
> set.seed(2013)
> x<-sort(c(letters,letters[sample(26,10,1)]))
> x<-x[duplicated(x)]
> x<-sort(c(x,unique(x)))
> _____
> Kevin Parent, Ph.D
> Korea Maritime University
> From: David Winsemius <dwinsem...@comcast.net>
> To: Kevin Parent <kspar...@yahoo.com> 
> Cc: "r-help@r-project.org" <r-help@r-project.org> 
> Sent: Thursday, August 8, 2013 3:03 PM
> Subject: Re: [R] Extracting only multiple occurrences
> 
> 
> On Aug 7, 2013, at 10:37 PM, Kevin Parent wrote:
> 
> > Hoping someone here can help me with this small problem.
> > set.seed(2013)
> > 
> > x<-sort(c(letters,letters[sample(26,10,1)]))
> > 
> > This gives a vector of 36 letters with some muliples (in this case, 
> > g,m,s,t,u,v,x,y). Now what I need is to get rid of the ones that only occur 
> > once and keep the multiples. I need the opposite of the unique() function. 
> > I expect this should be pretty easy but I can't see it. Anyone know a 
> > solution? Thanks in advance!
> > 
> > 
> ?duplicated
> 
> x[ duplicated(x) ]
> 
> 
> David Winsemius
> Alameda, CA, USA
> 
> 
> 

David Winsemius
Alameda, CA, USA

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to