Daryl Morris wrote:
>
> Hi,
> Sorry, I was too hasty. I see that the tolerance is in the
> documentation (and that "random" is the default tie-breaker).
>
> Would it be possible to allow tolerance to be a parameter?
>
> thanks, Daryl
>
>
Could you just use apply(x,1,which.max) ?
> x <- matrix(c(112345.568,112345.569,112345.567),1)
> x
[,1] [,2] [,3]
[1,] 112345.6 112345.6 112345.6
> apply(x,1,which.max)
[1] 2
It will presumably be less efficient than max.col (which
is implemented in C), and will automatically
pick the first value of the maximum if there are ties, but
should be OK for everyday use?
PS oddly enough apply(x,1,which.max) is faster -- maybe because
it doesn't try to deal with ties?
> benchmark(max.col(x),apply(x,1,which.max),replications=50000)
test replications user.self sys.self elapsed user.child
2 apply(x, 1, which.max) 50000 7.649 0.456 8.110 0
1 max.col(x) 50000 11.185 0.580 11.828 0
sys.child
2 0
1 0
--
View this message in context:
http://www.nabble.com/max.col-weirdness-tp23769831p23770927.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.