Skip to content
Prev 181583 / 398502 Next

Defining functions - an interesting problem

On Wed, 27 May 2009, utkarshsinghal wrote:

            
Look at the arguments to rank()
function (x, na.last = TRUE, ties.method = c("average", "first",
     "random", "max", "min"))

When you do rank(x, ties.method) you are passing "min" as the second 
argument to rank(), which is the na.last argument, not the ties.method 
argument.  This didn't give an error message because there weren't any NAs 
in your data.

You want
f1 = function(x,ties.method="average")rank(x,ties.method=ties.method)
which gives
[1] 1 1 3 4

 	-thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle