On Mon, 31 Oct 2005, Liaw, Andy wrote: >> From: Thomas Lumley >> >> On Sun, 30 Oct 2005, Jonathan Rougier wrote: >> >>> I'm not sure about this. Perhaps I am a dinosaur, but my feeling is >>> that if people are writing functions in R that might be subject to >>> simple operations like outer products, then they ought to be writing >>> vectorised functions! >> >> I would agree. How about an oapply() function that does >> multiway (rather >> than just two-way) outer products. Basing the name on "apply" would >> emphasize the similarity to other flexible, not particularly >> optimized >> second-order functions. >> >> -thomas > > I'll toss in my $0.02: The following is my attempt at creating a "general > outer" that works with more than two arguments. > > gouter <- function (x, FUN, ...) { > xgrid <- as.list(do.call("expand.grid", x)) > names(xgrid) <- NULL > array(do.call(deparse(substitute(FUN)), c(xgrid, list(...))), > dim = sapply(x, length), dimnames = x) > } >
Yes, that's the sort of thing I had in mind. The name "gouter" isn't exactly to my taste -- the point was that outer() is the fast but restricted function and that the general but slow function should have a different name (eg xapply or oapply). -thomas ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel