[R] String manipulation---mixed case
Spencer Graves
spencer.graves at pdf.com
Sun Dec 5 22:48:07 CET 2004
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 <renaud.lancelot at cirad.fr> 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
More information about the R-help
mailing list