probably you're looking for something like:
x <- c("nbsinst 0 sin en 3 ansnewzv Eleve", "nbsinst 1 sin en 3
ansnewzv Eleve",
"nbsinst 2+ sin en 3 ansnewzv Eleve", "nbsinst 0 sin en 3 ansnewzv
Basse",
"nbsinst 1 sin en 3 ansnewzv Basse", "nbsinst 2+ sin en 3 ansnewzv
Basse",
"nbsinst 0 sin en 3 ansnewzv Moyen", "nbsinst 1 sin en 3 ansnewzv
Moyen",
"nbsinst 2+ sin en 3 ansnewzv Moyen")
grep("2\\+ sin en 3 ans", x)
grep("1 sin en 3 ans", x)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: <gerald.jean@dgag.ca>
To: <s-news@wubios.wustl.edu>
Sent: Tuesday, August 22, 2006 5:14 PM
Subject: [S] Searching special characters in vector of strings.
Hello everyone,
how can I search for a string like
" 2+ sin en 3 ans"
in a vector of character strings as:
[1] "nbsinst 0 sin en 3 ansnewzv Eleve" "nbsinst 1 sin en 3 ansnewzv
Eleve"
[3] "nbsinst 2+ sin en 3 ansnewzv Eleve" "nbsinst 0 sin en 3 ansnewzv
Basse"
[5] "nbsinst 1 sin en 3 ansnewzv Basse" "nbsinst 2+ sin en 3 ansnewzv
Basse"
[7] "nbsinst 0 sin en 3 ansnewzv Moyen" "nbsinst 1 sin en 3 ansnewzv
Moyen"
[9] "nbsinst 2+ sin en 3 ansnewzv Moyen"
I know that I could use something like "\+" in regexpr but I would
like to
be able to do the search generally using the same code for searching,
for
example, for
" 1 sin en 3 ans"
in the same vector. The search is part of a function and the function
is
used extensively and, unfortunately, it bums when there is special
characters in the pattern to search for and / or in the vector of
strings
to search in.
Thanks,
Gérald Jean
Conseiller senior en statistiques, Actuariat
télephone : (418) 835-4900 poste (7639)
télecopieur : (418) 835-6657
courrier électronique: gerald.jean@dgag.ca
"In God we trust, all others must bring data" W. Edwards Deming
Le message ci-dessus, ainsi que les documents l'accompagnant, sont
destinés uniquement aux personnes identifiées et peuvent contenir des
informations
privilégiées, confidentielles ou ne pouvant être divulguées. Si vous
avez reçu ce message par erreur, veuillez le détruire.
This communication (and/or the attachments) is intended for named
recipients only and may contain privileged or confidential information
which is not
to be disclosed. If you received this communication by mistake please
destroy all copies.
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
|