[R] Generalized "Outer"
macrakis at alum.mit.edu
Fri Nov 21 21:49:51 CET 2008
Outer's arguments are restricted to atomic vectors or arrays built on
atomic vectors (though the documentation is not explicit on this
point). What is the equivalent for lists or arrays built on lists? My
particular application was testing the Kendall tau function. I tried
> outer( permn(3), permn(3), function(a,b)as.double(Kendall(a,b)$tau) )
I'd have hoped for something like
matrix( c( Kendall(permn(3)[], permn(3)[] )$tau,
Kendall(permn(3)[], permn(3)[] ) $tau,
but of course permn(3) is a list of vectors, not an atomic list.
If I want to define a version of outer for lists myself, I suppose the
clean way is to overload outer for the list class. But I'm not sure
how to do that since outer is not generic. Does this mean I need to
do something like
outer.vector <- outer;
outer <- <<define generic outer>>
etc.? Should I be redefining a built-in this way? Can someone point
me to documentation on this?
PS Should Kendall really be returning CSingles? The documentation
seems to say that they are to be used only in interfaces to outside
More information about the R-help