Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下数据集:
X v1 v2 class 1 12 10 A 2 11 13 B 3 14 15 A
我有两个 A 类对象和一个 B 类对象。我需要做的是获取这个矩阵并删除所有观察次数不满足阈值要求的类。如果我的阈值计数 = 2,我希望得到以下结果:
X v1 v2 class 1 12 10 A 3 14 15 A
我怎么能在 R 中实现这一点?
您可以使用table例如:
table
tt <- table(dat$class) dat[dat$class %in% names(tt[tt==threshold ]),]
例如:
dat <- read.table(text='X v1 v2 class 1 12 10 A 2 11 13 B 3 14 15 A',header=TRUE) threshold <- 2 tt <- table(dat$class) dat[dat$class %in% names(tt[tt==threshold]),]