如何获得一个数据帧的子集,该子集只包含在R中出现在集合中的元素多次

时间:2022-06-10 10:24:58

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.

我有一组数据,我想要一个子集。我希望子集定义为具有变量X值的那些行,它们出现不止一次。变量X是一个字符串。

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').

所以,例如,如果x由('help','me','me','with','this','this')组成,它将返回带有x值的行('me','me' ”, '这个,' 这个)。

Thank you so much for your help!

非常感谢你的帮助!

1 个解决方案

#1


14  

Something like this should work:

像这样的东西应该工作:

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

#1


14  

Something like this should work:

像这样的东西应该工作:

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