Skip to content

Extracting only multiple occurrences

10 messages · David Winsemius, Berend Hasselman, Rolf Turner +2 more

#
On Aug 7, 2013, at 10:37 PM, Kevin Parent wrote:

            
?duplicated

x[ duplicated(x) ]


David Winsemius
Alameda, CA, USA
#
On Aug 7, 2013, at 11:03 PM, David Winsemius wrote:

            
Also this may be of interest:

cran.r-project.org/doc/contrib/Short-refcard.pdf?

... but I was suprised to find that both duplicated and rle are absent from Short's refcards.
#
On Aug 7, 2013, at 11:23 PM, Kevin Parent wrote:

            
x[ duplicated(x) | duplicated(x, fromLast=TRUE) ]
#
On 08/08/2013 04:23 PM, Kevin Parent wrote:
Hi Kevin,
How about:

x[x %in% duplicated(x)]

Jim
#
On 08-08-2013, at 10:27, Jim Lemon <jim at bitwrit.com.au> wrote:

            
Don't you mean this

x[x %in% x[duplicated(x)]]   

Berend
#
On 08/08/13 20:27, Jim Lemon wrote:
Uh, I think you mean

     x[x %in% x[duplicated(x)]]

Another idear:

     tx <- table(x)
     tx <- tx[tx>1]
     rep(names(tx),tx)

Well, that's three lines as opposed to one, so not as good.  But it 
perhaps demonstrates
a useful tool to add to one's kit.

     cheers,

     Rolf
#
On 08/08/2013 06:52 PM, Berend Hasselman wrote:
Ah, yes, thanks.

Jim