Re: [R] Number of words in a string

From: Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com>
Date: Wed, 09 Apr 2008 21:01:18 +0530

Exactly...this is what I wanted... Can we also extract/remove the last word of the strings?

Example:
> C=c("My Dog", "Its really good", "Beautiful")
> sapply(strsplit(C, " "), length)

[1] 2 3 1

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: Markus Gesmann [mailto:Markus.Gesmann_at_libero.uk.com] Sent: Wednesday, April 09, 2008 9:00 PM
To: Shubha Vishwanath Karanth; r-help_at_stat.math.ethz.ch Subject: RE: [R] Number of words in a string

Would this:

sapply(strsplit(C, " "), length)

work for?

Markus Gesmann ©¦Associate Director©¦Libero Ventures Ltd, One Broadgate, London EC2M 2QS tel: +44 (0)207 826 9080©¦ dir: +44 (0)207 826 9085©¦fax: +44 (0)207 826 9090 ©¦www.libero.uk.com

A Lehman Brothers Company

AUTHORISED AND REGULATED BY THE FINANCIAL SERVICES AUTHORITY -----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Shubha Vishwanath Karanth Sent: 09 April 2008 16:21
To: r-help_at_stat.math.ethz.ch
Subject: [R] Number of words in a string

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 * London * New York * San Jos¨¦ * Singapore * www.ambaresearch.com

This e-mail may contain confidential and/or privileged i...{{dropped:13}}

This message is intended for the personal and confidential use for the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction or as an official statement of Libero Ventures Ltd. Email transmissions cannot be guaranteed to be secure or error-free. Therefore we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Any views or opinions presented are solely those of the author and do not necessarily represent those of Amba Holdings Inc., and/or its affiliates. Important additional terms relating to this email can be obtained at http://www.ambaresearch.com/disclaimer



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. Received on Wed 09 Apr 2008 - 15:47:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Apr 2008 - 16:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive