[R] problems with max.col ()

R.Heberto Ghezzo heberto.ghezzo at mcgill.ca
Thu Apr 24 20:52:32 CEST 2003


Hello, I think the following qualify as a bug
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
R 1.7.0 on Win98
As always thanks for any help



More information about the R-help mailing list