[R] Function modification: how to calculate values for every combination?
Lauri Nikkinen
lauri.nikkinen at iki.fi
Sun Sep 2 13:15:43 CEST 2007
Yeah, exactly. Thanks. The solution was too obvious :-)
Cheers,
Lauri
2007/9/2, dtrenkle at uni-osnabrueck.de <dtrenkle at uni-osnabrueck.de>:
> > Hello,
> >
> > I have a function like this:
> >
> > fun <- function (x, y) {
> > a <- log(10)*y
> > b <- log(15)*x
> > extr <- a-b
> > extr
> > }
> >
> > fun(2,3)
> > [1] 1.491655
> >
> > x <- c(1,2,3)
> > y <- c(4,5,6)
> > fun(x, y)
> > [1] 6.502290 6.096825 5.691360
> >
> > How do I have to modify my function that I can calculate results using
> > every combination of x and y? I would like to produce a matrix which
> > includes the calculated values in every cell and names(x) and names(y)
> > as row and column headers respectively. Is the outer-function a way to
> > solution?
> >
> > Best regards,
> > Lauri
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
> How about
>
> outer(x,y,fun)
>
> ?
>
> hth
>
> D. Trenkler
>
>
More information about the R-help
mailing list