Dear All, Is it possible to replace function with my own? I want to apply pca clustering, but to use some strange correlation function. I'm asking about replacing, say, mean() with new content of mean() and use standard other functions, which might use mean() as part. karsar
Hi Karsar, To replace mean you can make a new function with the same name: l = runif(10) mean(l) mean = function(x) return(1) mean(l) But there must be a better way... cheers, Paul On 09/06/2010 11:52 AM, Karen Sargsyan wrote:> Dear All, > > Is it possible to replace function with my own? I want to apply pca > clustering, but > to use some strange correlation function. I'm asking about replacing, > say, mean() with new content of mean() and use standard other > functions, which might use mean() as part. > > karsar > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 253 5773 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770
Karen Sargsyan wrote:> > Is it possible to replace function with my own? I want to apply pca > clustering, but to use some strange correlation function. I'm asking about > replacing, say, mean() with new content of mean() and use standard other > functions, which might use mean() as part. >The usual way would be to get the source code for the function you are trying to change (or, fast way, with getAnywhere(pca)), copy it to an editor, and make the changes. However, better always rename it before using, e.g. pcaKaren <- function.... If the code you are trying to change is not directly called, but indirectly, things are more complicated. In most cases, it's easiest to get the whole package, put it into a different namespace, and make the changes. Easiest does not mean not easy, though. Dieter -- View this message in context: http://r.789695.n4.nabble.com/replacing-functions-tp2528143p2528361.html Sent from the R help mailing list archive at Nabble.com.