[R] Working with string

Bert Gunter gunter.berton at gene.com
Sun Aug 11 16:56:33 CEST 2013


Oh, sorry. One type. Here's the correct version

On Sun, Aug 11, 2013 at 7:54 AM, Bert Gunter <bgunter at gene.com> wrote:
> Christofer:
>
> You may have to fortify the following a bit to allow for the
> possibility that some of your caps strings don't match. But other than
> that, I think this will do:
>
>> CH <- c("aBd", "sTb", "ABD", "dFDasd", "asd", "DFDASD")
>> caps <- CH %in%  toupper(CH)
>> noncaps <- CH[!caps]
>> chnew <- CH
>> chnew[caps] <- noncaps[match(CH[caps], toupper(noncaps))]
>> CH
> [1] "aBd"    "sTb"    "ABD"    "dFDasd" "asd"
> [6] "DFDASD"
>> chnew
> [1] "aBd"    "sTb"    "aBd"    "dFDasd" "asd"
> [6] "dFDasd"
>
> Cheers,
> Bert
>
> On Sun, Aug 11, 2013 at 5:39 AM, Christofer Bogaso
> <bogaso.christofer at gmail.com> wrote:
>> Hello again,
>>
>> Let say I have a lengthy character vector like:
>>
>> CH <- c("aBd", "sTb", "ABD", "dFDasd", "asd", "DFDASD")
>>
>> Now I want to create a vector like:
>>
>> CH_New <- c("aBd", "sTb", "aBd", "dFDasd", "asd", "dFDasd")  ## the 3rd and
>> 6th element replaced
>>
>> Basically, the goal is:
>>
>> If an element has all upper case then it will find another element with all
>> lower case or mix of upper/lower case. Then the all-upper-case element will
>> be replaced by that mix. If there is multiple match then chose the first
>> one.
>>
>>
>> Can somebody give me any pointer how can I achieve that?
>>
>> Thanks and regards,
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list