evt
evt

Reputation: 971

How to get a subset of a dataframe which only has elements which appear in the set more than once in R

I have a set of data which I would like a subset of. I would like the subset defined as those rows with a value for variable X which appears more than once. Variable X is a string.

So, for example, if x consisted of ('help','me,'me','with','this','this'), it would return the rows with the x values ('me','me','this,'this').

Thank you so much for your help!

Upvotes: 6

Views: 1334

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176638

Something like this should work:

x <- c('help','me','me','with','this','this')
x[duplicated(x, fromLast=TRUE) | duplicated(x)]

Upvotes: 14

Related Questions