Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare functions?

Tags:

function

r

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));
  #}
}
like image 783
sgibb Avatar asked Mar 09 '12 17:03

sgibb


People also ask

How do you compare two linear functions?

To compare linear functions, determine the rate of change and intercepts of each function.

What does it mean to compare two functions?

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.

How do you compare equations?

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.


1 Answers

You can use identical:

identical(m,mean)
like image 108
digEmAll Avatar answered Oct 21 '22 01:10

digEmAll