[R] test if text is part of vector
Rainer M Krug
r.m.krug at gmail.com
Fri Jan 20 13:01:54 CET 2012
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 20/01/12 12:50, Johannes Radinger wrote:
> Hello,
>
> this is a very simple question: How can I find out if a word is
> part of a list of words
>
> like: a <- "word1" b <- "word4"
>
> vector <- c("word1","word2","word3")
>
> I tried it with match(a,vector) but this gives the position of the
> word.
>
> I am not sure if and how that can be done with a logical operator
> like if: IF text is part of vector THEN print "is part"
>
> Probably a very easy thing to do, but I am missing the logical
> operator... and help(if) is not working
check out %in%
help:
?"%in%"
Cheers,
Rainer
>
> best regards, johannes
- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa
Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44
Fax (D): +49 - (0)3 21 21 25 22 44
email: Rainer at krugs.de
Skype: RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk8ZV7IACgkQoYgNqgF2egroawCfYAN/eOBMKN4VDTbBZtiBVGdS
LAUAnR+h9kg2INJTICiGIAUTfYm2fCbC
=Ws2h
-----END PGP SIGNATURE-----
More information about the R-help
mailing list