Re: [R] removing a word, the following space and the next word

2008-09-21 Thread Rolf Turner


On 21/09/2008, at 5:15 AM, jim holtman wrote:


x <- 'Mr Jones ate lunch and Mr Smith was tied'
gsub('(Mr\\.*)\\s+\\w+', "\\1  ", x)

[1] "Mr  ate lunch and Mr  was tied"


I don't get what the bit



is about.  If I do (just)

gsub('(Mr\\.*)\\s+\\w+', "\\1 ", x)

I get the desired result, i.e.


[1] "Mr  ate lunch and Mr  was tied"

cheers,

Rolf Turner




##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@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.


Re: [R] removing a word, the following space and the next word

2008-09-20 Thread jim holtman
> x <- 'Mr Jones ate lunch and Mr Smith was tied'
> gsub('(Mr\\.*)\\s+\\w+', "\\1  ", x)
[1] "Mr  ate lunch and Mr  was tied"
>
>


On Sat, Sep 20, 2008 at 2:24 AM, Bob Green <[EMAIL PROTECTED]>wrote:

>
> Hello,
>>
>
> I am hoping for advice as to how I could remove all words immediately
> following the words 'Mr' or 'Mr.' in  a csv file. For example, the following
> phrases are included in lines of text (along with other Mr) that could be
> anywhere in the file: "Mr Jones ate lunch" and "Mr Smith was tied".
>
>
> I want to remove the words Jones and Smith (etc) leaving the other text
> intact.
>
> Any suggestions are appreciated,
>
> regards
>
>
> Bob
>
> __
> R-help@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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] removing a word, the following space and the next word

2008-09-19 Thread Andrew Robinson
Hi Bob,

I recommend doing some background reading on regular expressions[1]
and using gsub().

Cheers

Andrew

[1] http://en.wikipedia.org/wiki/Regular_expressions

On Sat, Sep 20, 2008 at 04:24:36PM +1000, Bob Green wrote:
> 
> >Hello,
> 
> I am hoping for advice as to how I could remove all words immediately 
> following the words 'Mr' or 'Mr.' in  a csv file. For example, the 
> following phrases are included in lines of text (along with other Mr) 
> that could be anywhere in the file: "Mr Jones ate lunch" and "Mr 
> Smith was tied".
> 
> 
> I want to remove the words Jones and Smith (etc) leaving the other 
> text intact.
> 
> Any suggestions are appreciated,
> 
> regards
> 
> 
> Bob
> 
> __
> R-help@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.

-- 
Andrew Robinson  
Department of Mathematics and StatisticsTel: +61-3-8344-6410
University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/

__
R-help@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.


[R] removing a word, the following space and the next word

2008-09-19 Thread Bob Green



Hello,


I am hoping for advice as to how I could remove all words immediately 
following the words 'Mr' or 'Mr.' in  a csv file. For example, the 
following phrases are included in lines of text (along with other Mr) 
that could be anywhere in the file: "Mr Jones ate lunch" and "Mr 
Smith was tied".



I want to remove the words Jones and Smith (etc) leaving the other 
text intact.


Any suggestions are appreciated,

regards


Bob

__
R-help@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.