[R] how to transform string to "Camel Case"?

Rainer M. Krug Rainer at krugs.de
Mon Apr 15 14:19:15 CEST 2013


Liviu Andronic <landronimirc at gmail.com> writes:

> On Mon, Apr 15, 2013 at 9:25 AM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:
>> See for instance capitalize() in the R.utils package.
>>
> Unfortunately this also fails when NA values are present:
>  z <- c("R project", "hello world", "something Else", NA)
>> R.utils::capitalize(z)
> [1] "R project"      "Hello world"    "Something Else" "NANA"
>
> Any pointers how to work around that? Thanks,

would 

 R.utils::capitalize(z[is.character(z)])

work in your case?

Rainer


> Liviu
>
>
>> Henrik
>>
>> On Apr 14, 2013 11:51 PM, "Liviu Andronic" <landronimirc at gmail.com> wrote:
>>>
>>> Dear all,
>>> Given the following vector:
>>> > (z <- c('R project', 'hello world', 'something Else'))
>>> [1] "R project"      "hello world"    "something Else"
>>>
>>> I know how to obtain all capitals or all lower case letters:
>>> > tolower(z)
>>> [1] "r project"      "hello world"    "something else"
>>> > toupper(z)
>>> [1] "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
>>> strings:
>>> > tocamel(z)
>>> [1] "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')
>>>
>>>
>>> Regards,
>>> Liviu
>>>
>>>
>>> --
>>> Do you know how to read?
>>> http://www.alienetworks.com/srtest.cfm
>>> http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
>>> Do you know how to write?
>>> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
<#secure method=pgpmime mode=sign>

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer at krugs.de

Skype:      RMkrug



More information about the R-help mailing list