Re: [R] Number of words in a string

2008-04-09 Thread Hans-Joerg Bibiko
On 10 Apr 2008, at 07:43, Shubha Vishwanath Karanth wrote: > So powerful, the gsub... But I really don’t understand the how the > regular expressions like " *\\S+$", need to be used and how to make > best use of it... Any article/material/links that I can go through? A good starting point is:

Re: [R] Number of words in a string

2008-04-09 Thread Shubha Vishwanath Karanth
Number of words in a string On Apr 9, 2008, at 1:27 PM, Hans-Jörg Bibiko wrote: > > On 09.04.2008, at 17:46, Shubha Vishwanath Karanth wrote: >> To put it simple, >> >> C=c("My Dog", "Its really good", "Beautiful") >> >> Now

Re: [R] Number of words in a string

2008-04-09 Thread Charilaos Skiadas
On Apr 9, 2008, at 1:27 PM, Hans-Jörg Bibiko wrote: > > On 09.04.2008, at 17:46, Shubha Vishwanath Karanth wrote: >> To put it simple, >> >> C=c("My Dog", "Its really good", "Beautiful") >> >> Now, >> SOMEFUNCTION(C) should give: c("My", "Its really", "") > > SOMEFUNCTION <- function(x) gsub(" *\

Re: [R] Number of words in a string

2008-04-09 Thread Hans-Jörg Bibiko
On 09.04.2008, at 17:46, Shubha Vishwanath Karanth wrote: > To put it simple, > > C=c("My Dog", "Its really good", "Beautiful") > > Now, > SOMEFUNCTION(C) should give: c("My", "Its really", "") SOMEFUNCTION <- function(x) gsub(" *\\w+$", "", x) But be aware that this won't work for instance for

Re: [R] Number of words in a string

2008-04-09 Thread Gabor Grothendieck
3980 8031 | Mob +91 94 4886 4510 > > Bangalore * Colombo * London * New York * San José * Singapore * > > www.ambaresearch.com > > > > -Original Message- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROT

Re: [R] Number of words in a string

2008-04-09 Thread Gabor Grothendieck
trings without using ?strsplit ? > > Shubha Karanth | Amba Research > Ph +91 80 3980 8031 | Mob +91 94 4886 4510 > Bangalore * Colombo * London * New York * San José * Singapore * > www.ambaresearch.com > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROT

Re: [R] Number of words in a string

2008-04-09 Thread Hans-Joerg Bibiko
On 9 Apr 2008, at 17:44, Shubha Vishwanath Karanth wrote: > Got all the answers using ?strsplit... Is there any way without > using string split?... More specifically... How can I just extract > the last word in all the strings without using ?strsplit ? Oops, sorry. gsub(" *\w+$", "", C) sh

Re: [R] Number of words in a string

2008-04-09 Thread Shubha Vishwanath Karanth
on * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: Wednesday, April 09, 2008 9:01 PM To: Markus Gesmann; [EMAIL PROTECTED] Subject: Re: [R] Number of words in a st

Re: [R] Number of words in a string

2008-04-09 Thread Hans-Joerg Bibiko
Something like that? gsub(" {1,}\w+$", "", C) __ 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,

Re: [R] Number of words in a string

2008-04-09 Thread Shubha Vishwanath Karanth
* New York * San José * Singapore * www.ambaresearch.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hans-Joerg Bibiko Sent: Wednesday, April 09, 2008 9:10 PM To: [EMAIL PROTECTED] Subject: Re: [R] Number of words in a string On 9 Apr 2008, at 17:29

Re: [R] Number of words in a string

2008-04-09 Thread Christos Hatzis
length(unlist(strsplit(C, ' '))) > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Shubha > Vishwanath Karanth > Sent: Wednesday, April 09, 2008 11:21 AM > To: [EMAIL PROTECTED] > Subject: [R] Number of words in a

Re: [R] Number of words in a string

2008-04-09 Thread Shubha Vishwanath Karanth
31 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: Markus Gesmann [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 09, 2008 9:00 PM To: Shubha Vishwanath Karanth; [EMAIL PROTECTED] Subject: RE: [R] Nu

Re: [R] Number of words in a string

2008-04-09 Thread Hans-Joerg Bibiko
On 9 Apr 2008, at 17:29, Markus Gesmann wrote: > Would this: > > sapply(strsplit(C, " "), length) > > work for? or length(unlist(strsplit(C, " "))) --Hans __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do rea

Re: [R] Number of words in a string

2008-04-09 Thread Shubha Vishwanath Karanth
ew York * San José * Singapore * www.ambaresearch.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: Wednesday, April 09, 2008 8:51 PM To: [EMAIL PROTECTED] Subject: [R] Number of words in a string Hi R, A quick quest

Re: [R] Number of words in a string

2008-04-09 Thread Markus Gesmann
REGULATED BY THE FINANCIAL SERVICES AUTHORITY -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: 09 April 2008 16:21 To: [EMAIL PROTECTED] Subject: [R] Number of words in a string Hi R, A quick question: How do we find the

[R] Number of words in a string

2008-04-09 Thread Shubha Vishwanath Karanth
Hi R, A quick question: How do we find the number of words in a string? Example: C="Have a nice day" And the number of words should be 4. any built in function or?... Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo *