Skip to content
Prev 256926 / 398506 Next

Is there a better way to parse strings than this?

Thanks for the suggestions, they were all exactly what I was looking for.
(I knew that had to be a more elegant way then my brute force method)

One question though.

I was playing around with strsplit but couldn't get it to work, I realised
my problem was that I was using "." as the string.

I was trying strsplit(string,"\.\.\.") as per the suggestion in Venables
and Ripleys book to "(use '\.' to match '.')", which is in the Regular
expressions section.

I noticed that in the suggestions sent to me people used:
strsplit(test,"\\.\\.\\.")


Could anyone please explain why I should have used "\\.\\.\\." rather than
"\.\.\."?



Chris Howden
Founding Partner
Tricky Solutions
Tricky Solutions 4 Tricky Problems
Evidence Based Strategic Development, IP Commercialisation and Innovation,
Data Analysis, Modelling and Training
(mobile) 0410 689 945
(fax / office) (+618) 8952 7878
chris at trickysolutions.com.au


-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com]
Sent: Wednesday, 13 April 2011 10:55 PM
To: Chris Howden
Cc: r-help at r-project.org
Subject: Re: [R] Is there a better way to parse strings than this?

On Wed, Apr 13, 2011 at 12:07 AM, Chris Howden
<chris at trickysolutions.com.au> wrote:
I
are
Try this:
+ "A5.Brands.bought...Solver")
[,1]               [,2]
[1,] "A5.Brands.bought" "Dulux"
[2,] "A5.Brands.bought" "Haymes"
[3,] "A5.Brands.bought" "Solver"
V1     V2
1 A5.Brands.bought  Dulux
2 A5.Brands.bought Haymes
3 A5.Brands.bought Solver


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com