[R] outer

Jagat Sheth shethj at epi.wustl.edu
Thu Mar 15 19:16:56 CET 2001


Hi Oliver,

>>> Olivier Martin <olivier.martin at inrialpes.fr> 03/15 11:11 AM >>>
Dear r-plus users,

i would like to use outer in the following case  outer(x,y,FUN="fun")
i suppose that my function fun is of the following form:
fun<-function(x,y)
{
if(y>x) return(x+y)
if(y<=x) return(0)
}
My problem is that the command outer(x,y,FUN="fun") return me a
null matrix instead of an upper triangular matrix.
Is somebody have a solution ?

The arguments x,y in fun are not labelling the cell indices in the outer product. Here are a couple simple examples of what fun will do for you.

> x <- 1:3
> y <- 1:3
> outer(x,y,FUN="fun")
     [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0    0    0
[3,]    0    0    0

(Since x=y above, fun(x,y)=0 always)

> x <- 1:3
> y <- 2:4
> outer(x,y,FUN="fun")
     [,1] [,2] [,3]
[1,]    3    4    5
[2,]    4    5    6
[3,]    5    6    7
> 


Thanks for your help.

Jagat

--
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
Olivier MARTIN               phone: (33) 04 76 61 53 55
Projet IS2                               06 08 67 93 42
INRIA Rhone-Alpes            fax  : (33) 04 76 61 54 77
655, Av. de l'Europe
Montbonnot                  e-mail:olivier.martin at inrialpes.fr 
38334 Saint Ismier cedex
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list