Hi,
I ran into an interesting question from one of our users. He had an array
of about 3000 by 300 by 3. He tried to use apply to sum the last dimension:
result <- apply(array, c(1,2), sum)
I'm not sure he was ever able to get the result. He was surprised
because he could use apply over different dimensions and had no problem:
wrong.result <- apply(array, c(2,3), sum)
I suggested that he simply break down the problem into a simple
summation:
result <- array[,,1] + array[,,2] + array[,,3]
That executed very fast.
My question is "Has anybody constructed a list of functions that do not
scale well under certain circumstances?" I remember seeing something
within the last year about outer being very slow for long vectors and
clearly, there are some problems with apply.
Thanks.
Dave
|