That's great, Peter.

For pedestrians like me who are not quite as facile with regular expressions, the following seems slightly more readable:

s <- "the quick red fox jumps over the lazy brown dog"
ss <- strsplit(s, " ")[[1]]
ss1 <- substring(ss, 1,1)
ss2 <- substring(ss, 2)
paste(toupper(ss1), ss2, sep="", collapse=" ")

[1] "The Quick Red Fox Jumps Over The Lazy Brown Dog"

     Best Wishes,
     spencer graves

Peter Dalgaard wrote:

Renaud Lancelot <[EMAIL PROTECTED]> writes:



This question was posted a while ago and answered by Christian
Hoffmann. I wrapped it in a small function:

CapLeading <- function (string){


...

Version of same:

s <- "the quick red fox jumps over the lazy brown dog"
ss <- strsplit(s, " ")[[1]]
ss1 <- sub("(.).*", "\\1", ss)
ss2 <- sub(".", "", ss)
paste(toupper(ss1), ss2, sep="", collapse=" ")






-- Spencer Graves, PhD, Senior Development Engineer O: (408)938-4420; mobile: (408)655-4567

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to