Hi Bhupendrasinh,

No problem.
One more solution that works:

gsub("@.*?\\s","",x)
#[1] "Even in the mid-west spring is hardly for 3 weeks, while the scenario is 
different."

A.K.



________________________________
From: Bhupendrasinh Thakre <vickytha...@gmail.com>
To: arun <smartpink...@yahoo.com> 
Cc: David Winsemius <dwinsem...@comcast.net>; R help <r-help@r-project.org> 
Sent: Tuesday, September 18, 2012 2:49 PM
Subject: Re: [R] Simple String Operation.


Thanks David and Arun.... It solved my problem. 
Appreciate the help in understanding this.


Best Regards,


Bhupendrasinh Thakre

Disclaimer : 

The information contained in this communication is confidential and may be 
legally privileged. It is intended solely for the use of the individual or 
entity to whom it is adressed. If you are not the intended recipient you are 
hereby (a) notified that any disclosure, copying, distribution or taking any 
action with respect to the content of this information is strictly prohibited 
and may be unlawful, and (b) kindly requested to inform the sender immediately 
and destroy any copies. 



On Tue, Sep 18, 2012 at 12:41 PM, arun <smartpink...@yahoo.com> wrote:


>
>HI,
>This may also work:
>gsub("@\\S+\\s*","",x)
>#[1] "Even in the mid-west spring is hardly for 3 weeks, while the scenario is 
>different."
>#or
>gsub("@\\w+\\s*","",x)
>#[1] "Even in the mid-west spring is hardly for 3 weeks, while the scenario is 
>different."
>
>A.K.
>
>
>----- Original Message -----
>From: David Winsemius <dwinsem...@comcast.net>
>To: Bhupendrasinh Thakre <vickytha...@gmail.com>
>Cc: r-help@r-project.org
>Sent: Tuesday, September 18, 2012 12:58 PM
>Subject: Re: [R] Simple String Operation.
>
>
>On Sep 18, 2012, at 9:35 AM, Bhupendrasinh Thakre wrote:
>
>> Hi List,
>>
>> This is kind of very simple but I am not able to understand how it works...
>> I have a sentence like "Even in the mid-west spring is hardly for 3 weeks,
>> while @south the scenario is different."
>>
>> There are some more example of the same nature and don't know the source
>> yet.
>> What i want to do is remove word after "@"..
>>
>> Solution i think of.
>>
>>   1. gsub("@$","",string)  or gsub("@\\","",string)
>>   2. regex
>
>If you do not know how to use dput then just show some code that creates the 
>object of interest:
>
>> x <- "Even in the mid-west spring is hardly for 3 weeks, while @south the 
>> scenario is different."
>> gsub("@[[:alpha:]]+\\s", "", x)
>[1] "Even in the mid-west spring is hardly for 3 weeks, while the scenario is 
>different."
>
>I was puzzled that the documentation suggested this should work, but it only 
>removed the first letter in the word.
>
>> gsub("@\\w", "", x)
>[1] "Even in the mid-west spring is hardly for 3 weeks, while outh the 
>scenario is different."
>
>And this is how you use dput()
>>  dput(x)
>"Even in the mid-west spring is hardly for 3 weeks, while @south the scenario 
>is different."
>
>Notice that the output of dput on a character vector is not very revealing. It 
>is sometimes useful to use this method to shorten a long object:
>
>dput(head(x))
>
>
>>
>> Please provide me some guidance. Since* words after @ may have different
>> length so need some flexible solution*.
>>
>> Also sorry don't know how to put it in dput().
>>
>> Best Regards,
>>
>>
>> Bhupendrasinh Thakre
>>
>> *Disclaimer :*
>>
>> The information contained in this communication is confi...{{dropped:11}}
>>
>> ______________________________________________
>> 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.
>
>David Winsemius, MD
>Alameda, CA, USA
>
>______________________________________________
>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-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.

Reply via email to