[R] Number of words in a string
Shubha Vishwanath Karanth
shubhak at ambaresearch.com
Wed Apr 9 17:31:18 CEST 2008
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
More information about the R-help
mailing list