[R] An extention of outer() ?

From: Bogaso Christofer <bogaso.christofer_at_gmail.com>
Date: Thu, 07 Apr 2011 23:51:00 +0530

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],


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. Received on Thu 07 Apr 2011 - 18:00:09 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 - 18:20:28 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