[R] how to transform string to "Camel Case"?
pdalgd at gmail.com
Mon Apr 15 09:30:05 CEST 2013
On Apr 15, 2013, at 08:50 , Liviu Andronic wrote:
> Dear all,
> Given the following vector:
>> (z <- c('R project', 'hello world', 'something Else'))
>  "R project" "hello world" "something Else"
> I know how to obtain all capitals or all lower case letters:
>  "r project" "hello world" "something else"
>  "R PROJECT" "HELLO WORLD" "SOMETHING ELSE"
> I saw the tocamel() function in 'rapport', but it doesn't do what I
> want to achieve as it actually proceeds to camelCase/CamelCase the
>  "RProject" "helloWorld" "somethingElse"
> But how should I proceed to obtain Camel Case? Here's what I'd like to get:
> c('R Project', 'Hello World', 'Something Else')
That'll be capitalization, not camel case, camel-casing is when wordsHaveHumps inTheMiddle.
As for actually solving your problem, I'd try googling for "regular expression to capitalize word" and convert to use with gsub(). (I did do the googling, but regexps being what they are - unreadable gibberish at first sight - I thought I'd leave the hard work for others...). Or, as Pascal points out: example(toupper).
> Do you know how to read?
> Do you know how to write?
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help