[R] Generate temporary objects or not?

Zsombor Cseres-Gergely z.cseres-gergely at ucl.ac.uk
Tue Feb 27 16:37:31 CET 2001


Dear all,

Playing with a toy problem, I wondered how much it costs to generate
`internal' objects in a function that are not strictly needed. An example:

mean(apply(t(matrix(as.vector(x) - x0 / h, , nrow=nrow(x), ncol=ncol(x))), c(2) epakern, dim)) / h^dim

It would be more _readable_ if I defined the object inside the apply(), stick
it there and rm() after, but my feeling is that creating it and than removing
is costlier. (If the above structure is too simple, imagine something more
complicated) Am I right, it does not matter, since it is created inside anyway?

Another question is if apply() could feed the data into the nonfirst
argument of the function applied. I have clue just for the first.

Thank you,
Zsombor Cseres-Gergely


PS: The example is the most naive way for constructing a kernel density
estimator. But yes, I have VR[MASS] and locfit installed, and I know that this is
inefficient. Just a toy. :)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list