使用R - 删除行时,值重复少于3次 [英] using R - delete rows when a value repeated less than 3 times

查看:235
本文介绍了使用R - 删除行时,值重复少于3次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有10行和3列的框架

frame with 10 rows and 3 columns

    a   b c
1   1 201 1
2   2 202 1
3   3 203 1
4   4 204 1
5   5 205 4
6   6 206 5
7   7 207 4
8   8 208 4
9   9 209 8
10 10 210 5

我想删除所有行其中c列中相同的值重复少于3次。
在这个例子中,我想删除第6,9和10行(我的真实data.frame有5000行和25列)
我试图使用函数rle来做,但是我不断得到错误的解决方案
任何帮助?谢谢!

I want to delete all rows where the same value in the column "c" repeated less than 3 times. In this example I want to remove rows 6, 9 and 10. (my real data.frame has 5000 rows and 25 cols) I tried to do it using the function rle, but I keep getting the wrong solution. any help? thanks!

推荐答案

建立在

Building on Joshua's answer:

Data[Data$c %in% names(which(table(Data$c) > 2)), ]

这篇关于使用R - 删除行时,值重复少于3次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆