Re: [R] String manipulation and formatting

From: Bashir Saghir (Aztek Global) <Saghir.Bashir_at_ucb-group.com>
Date: Tue 18 Jul 2006 - 19:04:16 EST


As I am trying to maintain consistency with some SAS macros I prefer not to change the "standard definitions" in use at the moment. If I change things too much I don't think many people with use my new functions.

Thanks,
Saghir

-----Original Message-----
From: sean.oriordain@gmail.com [mailto:sean.oriordain@gmail.com] On Behalf Of Sean O'Riordain
Sent: Tuesday, July 18, 2006 10:50
To: Bashir Saghir (Aztek Global)
Cc: r-help@R-project.org
Subject: Re: [R] String manipulation and formatting

Does it have to be a stop char ".", or could it be a separate parameter, i.e. put in a comma, then the 10 becomes an integer...

s/

On 18/07/06, Prof Brian Ripley <ripley@stats.ox.ac.uk> wrote:
> On Tue, 18 Jul 2006, Bashir Saghir (Aztek Global) wrote:
>
> > Thanks to Richard, Gabor and Marc for some nice solutions to my request.
> >
> > I have a new problem:
> >
> > > xify(30.10)
> > [1] "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.X"
> > > xify(30.11)
> > [1] "XXXXXXXXXXXXXXXXXXX.XXXXXXXXXXX"
> >
> > The problem originates from:
> >
> > > as.numeric(unlist(strsplit(as.character(15.10), "\\.")))
> > [1] 15 1
> > > as.numeric(unlist(strsplit(as.character(15.11), "\\.")))
> > [1] 15 11
> >
> > It seems to boils down to:
> >
> > > as.character(15.10)
> > [1] "15.1"
> >
> > A simple solution is:
> >
> > > xify("15.10")
> > [1] "XXXXX.XXXXXXXXXX"
> >
> > I was wondering if there is a simple way for xify to see the zero of the
10
> > without having to force the user to add quotes around the format?
>
> No, as the parser has converted '15.10' to a numeric constant.
>
> What is the problem with asking users to enter strings as strings?
>
> --
> Brian D. Ripley, ripley@stats.ox.ac.uk
> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel: +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>



Legal Notice: This electronic mail and its attachments are i...{{dropped}}

R-help@stat.math.ethz.ch 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 Tue Jul 18 19:09:37 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 18 Jul 2006 - 20:17:08 EST.

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