Here is an even faster one; the general point is to create a properly
vectorized custom function/expression:
mymean <- function(x, y, z) (x+y+z)/3
a = data.frame(matrix(1:3e4, ncol=3))
attach(a)
print(system.time({r3 = mymean(X1,X2,X3)}))
detach(a)
# Yields:
# [1] 0.000 0.010 0.005 0.000 0.000
f,info="Where is the data?")
#
# END OF CODE
Further Remarks
---
The rationale behind being able to extend S3 data.frames with S4 classes
is that
(a) there is so much legacy code for data.frames (they are the
foundation of the data part in "programming with data");
(b) S4 classes allow for validation, multiple dispatch, etc.
I also wonder why the R developers chose this "setOldClass" way of
making use of S3 classes rather than adding a clean set of wrapper
classes that delegate calls to them cleanly down to their resp. S3
companions (i.e. a "Methods" package (capital "M") with "Character",
"Numeric", "List", "Dataframe", etc.). The present situation appears to
be somewhat messy.
Anyway -- a great tool and great work!
Cheers!
Ulf Martin
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel