Wolfram Fischer a �crit :

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

______________________________________________
[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


cap.leading <- function (string) { fn <- function(x) { v <- unlist(strsplit(x, split = " ")) u <- sapply(v, function(x) { x <- tolower(x) substring(x, 1, 1) <- toupper(substring(x, 1, 1)) x }) paste(u, collapse = " ") } unname(sapply(string, fn)) }

> cap.leading(c( "this is an element of the vector of strings", "second element" ))
[1] "This Is An Element Of The Vector Of Strings" "Second Element"


Best,

Renaud

--
Dr Renaud Lancelot, v�t�rinaire
C/0 Ambassade de France - SCAC
BP 834 Antananarivo 101 - Madagascar

e-mail: [EMAIL PROTECTED]
tel.:   +261 32 40 165 53 (cell)
        +261 20 22 665 36 ext. 225 (work)
        +261 20 22 494 37 (home)

______________________________________________
[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