我想根据两个条件删除一些行。 这是我的代码根据r中的多个条件删除行
test <-datasetjoin[!(datasetjoin$Occupation == "Clerical" & datasetjoin$AvgMonthSpend > 58.515),]
是否有可能以更优雅的方式获得相同的结果?
test <- test[!(test$Occupation == "Management" & test$AvgMonthSpend > 59.24),] test <- test[!(test$Occupation == "Manual" & test$AvgMonthSpend > 54.28),] test <- test[!(test$Occupation == "Professional" & test$AvgMonthSpend > 60.08),]
test <- test[!(test$Occupation == "Skilled Manual" & test$AvgMonthSpend > 57.06),] test <- test[!(test$NumberCarsOwned == "1" & test$YearlyIncome > (81300-51140) * 1.5 + 81300),]
预先感谢
Occupation MonthlySpend
Clerical 60
Management 59
Clerical 62
Clerical 58
Clerical 63
Management 56
Management 58
如果职业=文书及MonthlySpend> 60然后丢弃这些行 如果职业=管理和MonthlySpend> 57然后丢弃这些行。 最后我应该得到这样的:
Occupation MonthlySpend
Clerical 58
Management 56
请为您的问题提供[可重现的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 –
@AdamQuek请检查帖子,我用一个例子编辑。有没有办法做到这一点与循环?或应用()? –