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

From: Bert Gunter <gunter.berton_at_gene.com>
Date: Thu, 26 May 2011 15:16:21 -0700

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.

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

______________________________________________
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.
Received on Thu 26 May 2011 - 22:22:34 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 26 May 2011 - 22:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive