Skip to content

outer

3 messages · Olivier MARTIN, Kaspar Pflugshaupt, Achim Zeileis

#
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 ?

Thanks for your help.



--
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-


-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20010315/4496c794/attachment.html
#
On Thursday 15 March 2001 18:11, Olivier Martin wrote:

            
r-plus? That's new! :-)
you would have to change the if() clause: x and y are your data, not indices.

Try this:

m <- outer(x,y,FUN="+")
m[lower.tri(m, diag=T)] <- 0

Cheers

Kaspar
#
Olivier Martin wrote:
If you supply vectors to if(y>x), then just the first element is
actually used. ifelse does the job:

fun <- function(x,y) { ifelse(y>x, x+y, 0) }

should solve your problem
Achim

---------------------------
Institut f?r Statistik
Technische Universit?t Wien
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._