Skip to content
Prev 74997 / 398502 Next

Avoiding for loop

On 8/4/05, Matt Crawford <mcrawford at gmail.com> wrote:
idx <- seq(length = max(rawdata, 0))
X <- outer(rawdata[,1], idx, "==") - outer(rawdata[,2], idx, "==")

Note that we did not have to predefine X and it also works if rawdata
has zero rows:

   rawdata <- matrix(0, nr = 0, nc = 2) 

in which case it gives a 0 by 0 matrix.