tabulate

Bill Venables William.Venables@cmis.CSIRO.AU
Tue, 25 Jan 2000 08:46:06 +1000


> Bill Venables <William.Venables@cmis.CSIRO.AU> writes:
> 
> > table() should be the usual function for everyday use (and using
> > this makes the change to tabulate() unnecessary), but on R the
> > difference in speed between table() and tabulate() can be
> > dramatic.  I would suggest improving the efficiency of table()
> > should be a fairly high priority.
> 
> Would you happen to have a simple example showing the inefficiency? I
> just had a glimpse at the code and it would seem that there are some
> extraneous coercions from integer to double precision and back, which
> could be fairly easily removed.

OK Peter.  This is the first one I cooked up:

Version 0.90.1  (December 15, 1999)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type    "?license" or "?licence" for distribution details.

R is a collaborative project with many contributors.
Type    "?contributors" for a list.

Type    "demo()" for some demos, "help()" for on-line help, or
        "help.start()" for a HTML browser interface to help.
Type    "q()" to quit R.

[Previously saved workspace restored]

> m <- rpois(100000, 1)
> tabulate(m)
[1] 36891 18399  6064  1519   309    50     4     1
> table(m)
m
    0     1     2     3     4     5     6     7     8 
36763 36891 18399  6064  1519   309    50     4     1 
> system.time(tabulate(m))
[1] 0.11 0.00 0.00 0.00 0.00
> system.time(table(m))
[1] 2.90 0.16 4.00 0.00 0.00
> version
         _                   
platform sparc-sun-solaris2.7
arch     sparc               
os       solaris2.7          
system   sparc, solaris2.7   
status                       
major    0                   
minor    90.1                
year     1999                
month    December            
day      15                  
language R                   
> 

-- 
-----------------------------------------------------------------
Bill Venables, Statistician, CMIS Environmetrics Project.

Physical address:                            Postal address:
CSIRO Marine Laboratories,                   PO Box 120,       
233 Middle St, Cleveland, Qld, 4163          Cleveland, Qld, 4163
AUSTRALIA                                    AUSTRALIA

Tel: +61 7 3826 7251           Email: Bill.Venables@cmis.csiro.au     
Fax: +61 7 3826 7304      http://www.cmis.csiro.au/bill.venables/


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