From: McGehee, Robert <Robert.McGehee_at_geodecapital.com>

Date: Wed 13 Apr 2005 - 03:30:37 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!

http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Apr 13 03:38:57 2005

Date: Wed 13 Apr 2005 - 03:30:37 EST

This short function capitalizes the first letter of each word in a
character string, which is what I think you want.

capitalize <- function(x) {

x <- strsplit(x, " ")

for (i in seq(along = x)) {

substr(x[[i]], 1, 1) <- toupper(substr(x[[i]], 1, 1))
}

sapply(x, function(z) paste(z, collapse = " "))
}

Robert

-----Original Message-----

From: Wolfram Fischer [mailto:wolfram@fischer-zim.ch]
Sent: Monday, April 11, 2005 6:22 AM

To: r-help@stat.math.ethz.ch

Subject: [R] How to change letters after space into capital letters

What is the easiest way to change within vector of strings each letter after a space into a capital letter?

E.g.:

c( "this is an element of the vector of strings", "second element" )
becomes:

c( "This Is An Element Of The Vector Of Strings", "Second Element" )

My reason to try to do this is to get more readable abbreviations.
(A suggestion would be to add an option to abbreviate() which changes
letters after space to uppercase letters before executing the
abbreviation

algorithm.)

Thanks - Wolfram

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!

http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Apr 13 03:38:57 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:31:07 EST
*