# [R] problems with max.col()

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Apr 24 18:27:58 CEST 2003

```On Thu, 24 Apr 2003, heberto ghezzo wrote:

> Hello, I think the following qualify as a bug.

>From ?max.col

Details:

Ties are broken at random.  The determination of ``tie'' assumes
^^^^^^^^^^^^^^^^^^^^^^^^^^
that the entries are probabilities: there is a relative tolerance
of 1e-5, relative to the largest entry in the row.

> given:
> x<-c(1,2,3,4,2,4,2,2,4,2,2,2,4,3,2,1)
> z<-embed(x,4)
> z
>       [,1] [,2] [,3] [,4]
>  [1,]    4    3    2    1
>  [2,]    2    4    3    2
>  [3,]    4    2    4    3
>  [4,]    2    4    2    4
>  [5,]    2    2    4    2
>  [6,]    4    2    2    4
>  [7,]    2    4    2    2
>  [8,]    2    2    4    2
>  [9,]    2    2    2    4
> [10,]    4    2    2    2
> [11,]    3    4    2    2
> [12,]    2    3    4    2
> [13,]    1    2    3    4
> >
> max.col(z)
>  [1] 1 2 3 4 3 1 2 3 4 1 2 3 4
> Why?     ^ ^
> >        1 2
> or should be
>  [1] 1 2 3 4 3 4 2 3 4 1 2 3 4
> i.e. the first column with the max, or the last column
> same if
> z <- embed(x,5)
>  max.col(z)
>  [1] 2 1 2 5 1 5 3 4 1 2 3 4
> where it should be either of:
>  2 1 2 3 1 2 3 4 1 2 3 4
>  2 3 4 5 4 5 3 4 5 2 3 4
> or I am missing something?

> ?max.col does not return anything

It does on my system.

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

```