[R] Applying "toupper" to only portions of text strings

Bert Gunter gunter.berton at gene.com
Fri May 27 00:16:21 CEST 2011


Cute!
I don't think your proposed strategy is all that complicated, but see
the gsubfn package for a one-liner. In particular, check out

http://code.google.com/p/gsubfn/

where there is an example for your almost exact task.

-- Bert

On Thu, May 26, 2011 at 3:05 PM, Dennis Fisher <fisher at plessthan.com> wrote:
> Colleagues
>
> Assume that I have a vector containing some text strings, some of which contain a particular character.  I could like to apply "toupper" to the text before the character.  For example (in this case, "|" is the particular character):
>
> ORIGINAL:
>        TEXT    <- c("aaaa", "bbb|cc", "|ddd")
>
> AFTER APPLICATION OF toupper:
>        TEXT    <- c("AAAA", "BBB|cc", "|dddd")
>
> I could loop through each element, strsplit at the character, apply toupper to the first component, then paste each element together.  But, I hope that there is a simpler means to accomplish this.
>
> Thanks in advance.
>
> Dennis
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
> ______________________________________________
> 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.
>



-- 
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics
467-7374
http://devo.gene.com/groups/devo/depts/ncb/home.shtml



More information about the R-help mailing list