Re: [R] An extention of outer() ?

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Thu, 07 Apr 2011 15:06:06 -0300

Try this:

aperm(outer(x, y, fn1, y), c(3, 1, 2))[,,2]

On Thu, Apr 7, 2011 at 3:21 PM, Bogaso Christofer <bogaso.christofer_at_gmail.com> wrote:
> Dear all, as per my understanding, outer() function is to facilitate
> 2-dimensional function evaluation, like to evaluate f(x,y) for different
> values of x and y. However I have slightly modified version of that, where x
> is a matrix with, say, 5 rows and 2 columns and y is a vector. Let take
> following example:
>
>
>
> fn1 <- function(x1, x2, y) return (x1+x2+y)
>
>
>
> x <- matrix(1:10, nc = 2)
>
> y <- 1:5
>
>
>
> with this input, I want to construct a 5x5 matrix whose (1,1)th element will
> be : fn1(x[1,1], x[1,2], y[1]), (1,2)th element will be : fn1(x[1,1],
> x[1,2], y[2])..... (1,5)th element will be : fn1(x[1,1], x[1,2],
> y[5]).....similarly (2,1)th element will be : fn1(x[2,1], x[2,2],
> y[1])....etc
>
>
>
> If my 'x' object is a vector then I can easily use outer() function
> effectively. However for my present case, I am looking for some ***outer()
> like function*** to get the result effectively. Can somebody help me on how
> can I do that without using any for loop?
>
>
>
> Thanks and regards,
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org 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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
R-help_at_r-project.org 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.
Received on Thu 07 Apr 2011 - 18:08:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 19:20:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive