[英]Drop several factor levels in data frame in R
I needed to drop several factor levels from a data frame in R. With the solution provided in this question , I can get rid of one of them, but... is it possible to remove several factor levels in one effort?我需要从 R 中的数据框中删除多个因子级别。使用此问题中提供的解决方案,我可以摆脱其中之一,但是......是否可以一次删除多个因子级别?
I came up with this piece of code, subsetting as many times as factors needed to remove...我想出了这段代码,子集的次数与需要删除的因素一样多......
dino <- read.csv('/home/maxim/onset.csv', header=TRUE)
dino <- subset(dino, onset != "QT")
dino <- subset(dino, onset != "")
table(droplevels(dino)$onset)
It works fine in my case, but i was wondering if anyone knows a more direct way to do it.在我的情况下它工作正常,但我想知道是否有人知道更直接的方法。 (BTW, I'm not very profficient in R...) (顺便说一句,我不是很精通 R...)
@Matthew Plourde 提出的解决方案:
dino[! dino$onset %in% c('QT', ''), ]
@Joris Meys 提出的解决方案:
subset(dino, ! onset %in% c("QT",""))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.