Hi all, I would like to check if a string contains "." in it. If yes, I would like to know the position of "." in the string. Eg: X<-"NM1236.3" In above example, "." is at position 7. I tried functions grep() and match(). It seems they couldn't detect ".". Thanks in advance for your help, Sityee [[alternative HTML version deleted]]
Henrique Dallazuanna
2008-Oct-01 19:00 UTC
[R] Looking for position of character in a string
Try this:
gregexpr("\\.", X)
On Wed, Oct 1, 2008 at 3:56 PM, phoebe kong <sityeekong at gmail.com>
wrote:> Hi all,
>
> I would like to check if a string contains "." in it. If yes, I
would like
> to know the position of "." in the string.
>
> Eg: X<-"NM1236.3"
>
> In above example, "." is at position 7.
>
> I tried functions grep() and match(). It seems they couldn't detect
".".
>
>
> Thanks in advance for your help,
> Sityee
>
> [[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.
>
--
Henrique Dallazuanna
Curitiba-Paran?-Brasil
25? 25' 40" S 49? 16' 22" O
> s1 <- "Hello.World"> which(strsplit(s1, '')[[1]]=='.')[1] 6> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of phoebe kong > Sent: Wednesday, October 01, 2008 2:56 PM > To: r-help at r-project.org > Subject: [R] Looking for position of character in a string > > Hi all, > > I would like to check if a string contains "." in it. If yes, > I would like to know the position of "." in the string. > > Eg: X<-"NM1236.3" > > In above example, "." is at position 7. > > I tried functions grep() and match(). It seems they couldn't > detect ".". > > > Thanks in advance for your help, > Sityee > > [[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. >