Is this what you want:
> my.foo <- function( a, b ) a - b
> z <- combn(ncol(y), 2) # get all the combinations of 2 columns
> result <- do.call(cbind, lapply(seq(ncol(z)), function(.cols){
+ my.foo(y[,z[1,.cols]], y[, z[2, .cols]])
+ }))
>
>
> result
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
Maybe something like the code below?
There is surely a more elegant way of handling the indices, maybe with plyr?
-s
> xx <- array(1:6,c(3,2)); xx
[,1] [,2]
[1,]14
[2,]25
[3,]36
> yy <- array(1:12,c(3,4)); yy
[,1] [,2] [,3] [,4]
[1,]147 1
CORRECTION:
> my.foo <- function( a, b ) { c <- a - b; } #really more complex, but just
> to illustrate
--
View this message in context:
http://www.nabble.com/Doing--o--that-operates-on-columns-instead-of-atomics-tp22701363p22701400.html
Sent from the R help mailing list archive at Nabble.c
3 matches
Mail list logo