From Martin Maechler <maechler@stat.math.ethz.ch>  Thu Mar 19 11:21:39 1998
From: Martin Maechler <maechler@stat.math.ethz.ch> (Martin Maechler)
Date: Thu, 19 Mar 1998 12:21:39 +0100
Subject: a handy function "format.cardinal", looking for a proper name..
In-Reply-To: <Pine.OSF.3.96.980319121016.15933F-100000@alpha> (message from
 Philippe Lambert on Thu, 19 Mar 1998 12:11:33 +0100 (MET))
Message-ID: <199803191121.MAA07944@sophie.ethz.ch>


>>>>> "Philippe" == Philippe Lambert <phlamber@luc.ac.be> writes:

    Philippe> On Thu, 19 Mar 1998, Martin Maechler wrote:

    >> This is not a nice name (format is generic; cardinal is not a class)
    >> for a nice function, which I would like in several places in R code
    >> and therefore would like to become part of R (under a better name !)
    >> 
    >> format.cardinal <- function(i, sep="") paste(i,
    >> c("st","nd","rd","th")[pmin(4,i)], sep=sep)
    >> 
    >> # Try format.cardinal(sample(1:20))

    Philippe> Isn't it a problem?
Oh yes, course!
    >> format.cardinal(22)
    Philippe> [1] "22th"

Thank you Philippe!

So, the function will become a bit more complicated.
The following would be better, but is not yet the solution
[and yes, I must consult an English dictionnary or such...].

format.cardinal <- function(i, sep="")
   paste(i, c("st","nd","rd","th")[pmin(4,1+(i-1) %% 10)], sep=sep)

BTW:  This ``triggers'' an inconsistency  R <-> S-plus
      which I consider a bug in R:

R> -1 %% 10
[1] -1

S> -1 %% 10
[1] 9

------------

BTW:  I am still looking for a proper name for that function...,
	maybe "english.cardinal" ??

Martin Maechler <maechler@stat.math.ethz.ch>			<><
Seminar fuer Statistik, ETH-Zentrum SOL G1;	Sonneggstr.33
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1086
http://www.stat.math.ethz.ch/~maechler/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


a handy function "format.cardinal", looking for a proper name..
Martin Maechler