Skip to content
Prev 314804 / 398506 Next

pattern matching

HI,
str1<-"x$Expensive"
regexpr("\\$",str1)[1]
#[1] 2
?str2<-"x$Exp$Expression"
unlist(gregexpr("\\$",str2))
#[1] 2 6


A.K.




----- Original Message -----
From: Data Analytics Corp. <walt at dataanalyticscorp.com>
To: "r-help at R-project.org" <r-help at r-project.org>
Cc: 
Sent: Monday, January 7, 2013 4:22 PM
Subject: [R] pattern matching

Hi,

I have a simple question.? Suppose I have a string "x$Expensive". I want to find the position of the $ in this string; i.e., I want a function that returns 2.? I tried grep, regexpr, etc with no luck, unless I'm just using them incorrectly.? Any suggestions?

Thanks,

Walt

________________________

Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536
________________________
(V) 609-936-8999
(F) 609-936-3733
walt at dataanalyticscorp.com
www.dataanalyticscorp.com

______________________________________________
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.