我试图弄清楚如何通过引用从数据集中删除一组行。例如,使用此数据集:
testset <- data.table(date=as.Date(c("2013-07-02","2013-08-03","2013-09-04","2013-10-05","2013-11-06")),
yr = c(2013,2013,2013,2013,2013),
mo = c(07,08,09,10,11),
da = c(02,03,04,05,06),
plant = LETTERS[1:5],
product = as.factor(letters[26:22]),
rating = runif(25))
我想删除产品所在的所有行&#34; y&#34;。我不知道该怎么做。
答案 0 :(得分:-3)
您可以使用以下任一命令 -
testset_new <- subset(testset,product!="y")
或
testset_new <- testset[testset$product!="y",]