> allclasses <- c("physics", "chemistry", "statistics", "mathematics", "biology", "history", "english")
> registered <- c("physics", "mathematics", "history")
> which(allclasses %in% registered)
[1] 1 4 6
[1] 1 4 6
This also works with numeric vectors. For example, a numeric set B is a subset of A, and you want to select all those elements that are included in A but not B. You can do the following:
> A <- c(1, 2, 3, 5, 8, 13, 21, 34, 55, 89)
> B <- c(1, 5, 21, 89)
> A[!(A %in% B)]
[1] 2 3 8 13 34 55
No comments:
Post a Comment