is it possible to use the subset function by saying sth like subset(dataset, IA_LABEL not equal to "Er" or "Sie" or "Es" or "wird" or "gleich") ? what interests me is the "not 开发者_如何学Pythonequal to" operator, is there something like that for the subset function?
thanks, Katerina
If you are wanting to exclude all of those words, then you are better of using a combination of the negation (NOT) operator, !
, and set membership, %in%
.
wordList <- c("Er","Sie","Es","wird","gleich")
subset(dataset, !(IA_LABEL %in% wordList))
To make it case insensitive you might want to wrap each of them in toupper
or tolower
.
The not equal operator is written !=
See ?Comparison
for details.
An example using subset
:
> subset(airquality, Day != 1, select = -Temp)[1:5, ]
Ozone Solar.R Wind Month Day
2 36 118 8.0 5 2
3 12 149 12.6 5 3
4 18 313 11.5 5 4
5 NA NA 14.3 5 5
6 28 NA 14.9 5 6
Using the %nin%
function in Hmisc
require(Hmisc)
subset(dataset, IA_LABEL %nin% wordList)
精彩评论