Is there a way to compare whether two function objects are the same?
m <- mean
m == mean ## don't work
## this seems not to be the correct way:
functionBody(mean)==functionBody(m)
EDIT: Some more details. I have a function with two arguments (a matrix and a user-defined function which is applied columnwise, e.g. mean, median, ...). If the function is mean
I want to use colMean
instead (to save some running time).
foo <- function(m, fun) {
#if (fun==mean) {
# return(colMeans(m));
#} else {
return(apply(m, 2, fun));
#}
}
To compare linear functions, determine the rate of change and intercepts of each function.
Sometimes a problem asks us to compare two functions which are represented in different ways. For example, you might be given a table and a graph, and asked which function is greater for a particular value, or which function increases faster.
The comparison method, a procedure for solving systems of independent equations, starts by rewriting each equation with the same variable as the subject. Any of the variables may be chosen as the first variable to isolate. Each equation is now an isolated-subject equation, and equation where one variable is isolated.
You can use identical
:
identical(m,mean)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With