Skip to content
Prev 345522 / 398503 Next

which LETTERS?

On 10/11/2014 7:50 AM, Charles Stangor wrote:
This computes

LETTERS == c("A")

then returns the indices where it is TRUE.  Since LETTERS has 26 
elements, but "A" has only one, the "A" is repeated 26 times.  Only the 
first one matches LETTERS.
The c("A", "B") needs to be repeated 13 times to get to length 26. Only 
the first two match.
c("A", "B", "C") can't be repeated a whole number of times to extend to 
length 26, so it is repeated 8 2/3 times, and you get a warning.
You probably want to use

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

instead.

Duncan Murdoch