[R] need help

arun smartpink111 at yahoo.com
Thu Jun 14 05:50:30 CEST 2012


Hi,

For the example you gave, the regex below works:
> txt1<-"my name name name is micky"

> gsub("\\b(\\w+)\\b(\\s+)\\1\\2","",txt1)
[1] "my name is micky"

But, the expression is not a generalized one.
A.K.





----- Original Message -----
From: shilpa rai <raishilpa.bhu at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Wednesday, June 13, 2012 6:56 AM
Subject: [R] need help

hello
could you help in solving the following problem

I want to replace same consecutive words by a single word in a sentence..

for example --- my name name name is micky
so I want the output like this--my name is micky

I want this solution for a text file

can you tell me the code for it??

thanking you in anticipation

-- 
Shilpa Rai
MSc.(2011-2013)
Applied Statistics and Informatics
Indian Institute of Technology,Bombay

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




More information about the R-help mailing list