[R] Pattern Matching help

Samir Mishra sqmishra at excite.com
Wed Jan 17 13:04:31 CET 2001


Thanks in advance for any help I can get on this.

I'm trying to change variable names between 2 systems - R and old SPSS,
Oracle. I'm using the grep() and gsub() commands but I'm getting the
following result - 

> test.dat <- c("a", "b.c", "d.e.f", "p_q,r")

> test.dat
[1] "a"     "b.c"   "d.e.f" "p_q,r"

> grep(",", test.dat, value = TRUE, extended = FALSE)
[1] "p_q,r"

> grep("_", test.dat, value = TRUE, extended = FALSE)
[1] "p_q,r"

> #NOT WHAT I WANT, I EXPECT TO GET ONLY ELEMENTS 2 & 3 RETURNED
> grep(".", test.dat, value = TRUE, extended = FALSE)
[1] "a"     "b.c"   "d.e.f" "p_q,r"


And similarly, with gsub(), I get -
> gsub(",", "_", test.dat, extended = FALSE)
[1] "a"     "b.c"   "d.e.f" "p_q_r"

> gsub("_", ".", test.dat, extended = FALSE)
[1] "a"     "b.c"   "d.e.f" "p.q,r"

> #NOT WHAT I WANT
> gsub(".", "_", test.dat, extended = FALSE) #NOT WHAT I WANT
[1] "_"     "___"   "_____" "_____"


Am I doing something wrong? 

Samir.



> version
platform i386-pc-mingw32
arch     x86
os       Win32
system   x86, Win32
status
major    1
minor    2.0
year     2000
month    12
day      15
language R







Samir Mishra
===========================================
Please send replies to :
sqmishra at acm.org
===========================================





_______________________________________________________
Send a cool gift with your E-Card
http://www.bluemountain.com/giftcenter/


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list