Hopefully this may be of use to someone else. The function isn't
completely satisfying as apply doesn't deal nicely with functions that
return higher-dimensional arrays (eg. apply(a, 1, I)) and reduces 1-D
arrays to vectors (eg. apply(a,3,sum)). Any comments on the code
would be greatfully appreciated.