I am trying to make two subsets my data if any one of 5 columns (5-10) contains a factor within my list (keep.list) and one where none of the cols contain anything from the keep.list. Here's where I am so far but can't get it to subset right:
test.cols <- c(5:10)
keep.list <- c("dog","cat","mouse","bird")
data.sub.IN <- data.big[which(any(keep.list %in% data.big[test.cols])),]
data.sub.NOT.IN <- data.big[which(any(keep.list !%in% data.big[test.cols])),]
I think which()
and any()
can help but I might be wrong, and I don't know how to handle to "not included" case, as the usual !
command isn't working.