Ff Yy Ff Yy - 24 days ago 4
R Question

Subsetting a vector using multiple conditions

> which(LETTERS=="A")
[1] 1
> which(LETTERS=="B")
[1] 2


Can i use one statement in which to get the value of 1,2?

which(LETTERS=="B" or "A")
Error: unexpected symbol in "which(LETTERS=="B" or"

Answer
which(LETTERS == "A" | LETTERS == "B")

Or:

which(LETTERS %in% c("A", "B"))
Comments