[R] which LETTERS?
Ivan Calandra
ivan.calandra at univ-reims.fr
Mon Nov 10 14:03:17 CET 2014
Hi Charles,
I think you're looking for %in%:
which(LETTERS %in% c("A", "B", "C"))
See ?"%in%" for details
Basically, with "==", the vector c("A","B") or c("A","B","C") will be
recycled and compared with LETTERS, which is not what you want. You want
to match() LETTERS with the vector.
Maybe someone who better knows the correct terms will be able to explain
better how it works.
HTH,
Ivan
--
Ivan Calandra, ATER
University of Reims Champagne-Ardenne
GEGENA² - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calandra at univ-reims.fr
https://www.researchgate.net/profile/Ivan_Calandra
Le 10/11/14 13:50, Charles Stangor a écrit :
> I'm confused:
>
> Thanks in advance.
>
>> which(LETTERS == c("A"))
> [1] 1
>> which(LETTERS == c("A","B"))
> [1] 1 2
>> which(LETTERS == c("A","B","C"))
> [1] 1 2 3
> Warning message:
> In LETTERS == c("A", "B", "C") :
> longer object length is not a multiple of shorter object length
>
>
> Charles Stangor
> Professor
> Dept of Psychology
> University of Maryland
> Academic Achievement Research Group <http://www.charlesstangor.com/AARG>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list