6

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!

evt
  • 941
  • 2
  • 16
  • 24

1 Answers1

14

Something like this should work:

x <- c('help','me','me','with','this','this')
x[duplicated(x, fromLast=TRUE) | duplicated(x)]
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • 2
    You are pretty awesome. you know that, right? Thanks for teaching me the duplicated command! – evt May 25 '11 at 03:29