[R] Help with efficient double sum of max (X_i, Y_i) (X & Y vectors)

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Thu Feb 1 20:20:24 CET 2007


Jeff,

you can do

> sum1: \sum_i\sum_j max(X_i,X_j)
> sum2: \sum_i\sum_j max(Y_i,Y_j)

sum(x * (2 * rank(x) - 1))

> sum3: \sum_i\sum_j max(X_i,Y_j)

sum(outer(x, y, pmax))

Probably, the latter can be speeded up even more...
Z



More information about the R-help mailing list