[R] Generalized "Outer"

Stavros Macrakis 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
this

> 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)[[1]], permn(3)[[1]] )$tau,
                       Kendall(permn(3)[[1]], permn(3)[[2]] ) $tau,
                            ...),
                    length(permn(3)),
                    length(permn(3))  )

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?

Thanks,

           -s

PS Should Kendall really be returning CSingles?  The documentation
seems to say that they are to be used only in interfaces to outside
code.



More information about the R-help mailing list