Possible Duplicate:
Opposite of %in%
What is the opposite of
matrix[matrix%in%1,]?
!%in% does not work.
I would like to select items that do not contain a certain number.
R %not in% operator, opposite to %in%
You can use the following basic syntax to select all elements that are not in a list of values in R: ! (data %in% c(value1, value2, value3, ...))
To select variables from a dataset you can use this function dt[,c("x","y")] , where dt is the name of dataset and “x” and “y” name of vaiables. To exclude variables from dataset, use same function but with the sign - before the colon number like dt[,c(-x,-y)] .
If you find yourself using @Joshua's suggestion often, you could easily make your own %notin%
operator.
`%notin%` <- Negate(`%in%`)
'a' %notin% c('b', 'c')
# [1] TRUE
You want:
matrix[!matrix %in% 1,]
For clarity's sake, I prefer this, even though the parentheses aren't necessary.
matrix[!(matrix %in% 1),]
Also note that you need to be aware of FAQ 7.31: Why doesn't R think these numbers are equal?.
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