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 equal 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With