Skip to content

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

3 messages · Martin Maechler, Friedrich Leisch, Thomas Lumley

#

        
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#

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

            
Philippe> Isn't it a problem?
MM> Oh yes, course!
Philippe> [1] "22th"

MM> Thank you Philippe!

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

is probably a good idea :-)

.f
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Thu, 19 Mar 1998, Martin Maechler wrote:>
I would have though "ordinal" would be a better name.  Those things are
called ordinals, not cardinals.  This would also allow a language argument
to produce

ordinal(1:3,"english") 
"1st" "2nd" "3rd"
ordinal(1:3,"francais")
"1re" "2me" "3me"

and so on (we probably have people on R-devel who can supply rules
for most common languages using the Latin alphabet). 

On the other hand, aren't there GNU internationali{s,z}ation libraries
that handle this sort of thing?


Thomas Lumley
------------------------------------------------------+------
Biostatistics		: "Never attribute to malice what  :
Uni of Washington	:  can be adequately explained by  :
Box 357232		:  incompetence" - Hanlon's Razor  :
Seattle WA 98195-7232	:				   :
------------------------------------------------------------


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._