[R] outer question

Laura Holt lauraholt_983 at hotmail.com
Mon Aug 30 22:27:29 CEST 2004

Dear R People:

I need to construct a matrix of the order (pn-1) x (pn-1).

The elements can be constructed as
z[i,j] = pn - max(i,j)
for (i,j) in 1:(pn - 1)

I was messing with a toy example in which n=4, p=3 and tried to use outer:
>x <- 1:11
>y <- 1:11
Error in outer(x, y, function(x, y) 12 - max(x, y)) :
        dim<- : dims [product 121] do not match the length of object [1]

Is there a better way to do this, please?  I would like to avoid loops if 

Thanks in advance.

Laura Holt
mailto: lauraholt_983 at hotmail.com
R version 1.9.1 windows

More information about the R-help mailing list